EasyUI datagrid 多條件查詢


<script type="text/javascript">
 
        $(function () {
            $("#dg").datagrid({
                url: '',
                singleSelect: true,
                pagination: true,
                pageSize: 15,
                pageList: [5, 10, 15, 20, 30, 50, 80, 200],
                queryParams: form2Json("searchform"),  //關鍵之處
                //鎖定列
            frozenColumns: [[{
                field: 'ck', checkbox: true
            },
        ]],
            columns: [[{
                field: "be_id",
                title: "專家ID",
                hidden: true
            }, {
                field: "be_name",
                title: "專家姓名",
                align: 'left',
                width: 100
            }, {
                field: "be_post",
                title: "專家職稱",
                align: 'left',
                width: 200
 
            }, {
                field: "dt_id",
                title: "所屬科室",
                align: 'center',
                width: 100,
                formatter: function (value, row) {
                    return formatterDepartment(value)
                }
            }, {
                field: "be_intro",
                title: "專家簡介",
                align: 'left',
                width: 450
            }, {
                field: "be_order",
                title: "排序ID",
                align: 'center',
                width: 100
            }]],
            })//datagrid
 
 
          $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#dg').datagrid({ queryParams: form2Json("searchform") });   //點擊搜索
            });
 
        })
 
        //將表單數據轉為json
        function form2Json(id) {
 
            var arr = $("#" + id).serializeArray()
            var jsonStr = "";
 
            jsonStr += '{';
            for (var i = 0; i < arr.length; i++) {
                jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
            }
            jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
            jsonStr += '}'
 
            var json = JSON.parse(jsonStr)
            return json
        }
 
    </script>

HTML

<form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>專家檢索:</strong></td>
    <td height="30">
        <input type="text" name="keyword" size=20 >
        <select name="search_type" id="search_type" >
            <option value="-1">請選擇搜索類型</option>
            <option value="be_name" >按專家姓名</option>
            <option value="be_intro">按專家簡介</option>
        </select>
        <select name="search_dept" id="search_dept">
            <option value="-1">請選擇所屬科室</option>
        </select>
        <a id="submit_search">搜索</a>
    </td>
  </form>
  <table id="dg"></table>

 

queryParams: form2Json("searchform")  是關鍵,這個屬性是專門用來查詢的

  為搜索按鈕綁定click事件

       $("#submit_search").click(function () {
                $('#dg').datagrid({ queryParams: form2Json("searchform") });   //點擊搜索
            });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM