easyui datagrid 从后台加载过来数据筛选进行前台展示


//定义两个常量

var count = 0;
 var data;

为两个筛选条件的radio 按钮绑定单击事件

  //查看未审核合同
            function checkUnReview(obj) {
                $("#btabsDiv").find("input[type=radio]").not(obj).attr("checked", false);//使div下的radio只能单个被选中
                count++;
                if (count == 1) {
                    data = $("#maingrid").datagrid("getData");
                }
                $("#maingrid").datagrid("loadData", loadFilter(data, "待审核"));
            }
            //查看已审核合同
            function checkReview(obj) {
                count++;
                $("#btabsDiv").find("input[type=radio]").not(obj).attr("checked", false);
                //$("#maingrid").datagrid('reload');
                if (count == 1) {
                    data = $("#maingrid").datagrid("getData");
                }

                $("#maingrid").datagrid("loadData", loadFilter(data, "已审核"));//重新加载数据
            }
            function loadFilter(data, status) {//重新组织datagrid数据,把符合条件的内容加到定义的json字符串中。
                var value = {
                    total: data.total,
                    rows: []
                };
                var x = 0;
                for (var i = 0; i < data.rows.length; i++) {
                    if (data.rows[i].status2 == status) {
                        value.rows[x++] = data.rows[i];
                    }
                }
                return value;
            }

在data-options中添加onLoadSuccess事件,在数据加载成功时触发。用于默认加载符合某个条件的数据

<table id="maingrid" class="easyui-datagrid  tab01" title="" style="width: 100%;height: 100%" data-options="rownumbers:true,nowrap:true,striped:true,remoteSort:true,sortName:'createdate',sortOrder:'desc',singleSelect:true,pagination:true,method:'get',url: '/ashx/Contract/reviewContractData.ashx?module=reviewServiceContract', toolbar:'#tb',onLoadSuccess:function(data1){
                count++;
                if(count==1)
                {
                 data = $('#maingrid').datagrid('getData');
                 $('#maingrid').datagrid('loadData', loadFilter(data, '待审核'));
                }
                }">
                <thead>
                    <tr>
                         <th data-options="field:'ck',checkbox:true"></th>
                            <th data-options="field:'isFrame',align:'center',width:'100px' ">
                            是否为框架合同
                        </th>
                          <th data-options="field:'createmanname',align:'center',width:'100px' ">
                            创建人
                        </th>
                        <th data-options="field:'createdate',align:'center',width:'100px'">
                            创建日期
                        </th>
                            <th data-options="field:'reviewtime',width:'120px'">
                            审批时间
                        </th>
                            <th data-options="field:'status2',width:'100px' ">
                            审核状态
                        </th>
                           <th data-options="field:'status',width:'120px'">
                            状态
                        </th>
                        <th data-options="field:'contractNo',sortable:'true',width:'150px'  ">
                            合同编号
                         </th>
                          <th data-options="field:'isFrame',width:'100px' ">
                            是否为框架合同  
                        </th>
                         <th data-options="field:'buyer',align:'left',width:'200px' ">
                            甲方(买方)  
                        </th>
                         <th data-options="field:'seller',align:'left',width:'200px' ">
                            乙方(卖方)
                         </th>
                             <th data-options="field:'partyC',align:'left',width:'200px' ">
                         丙方
                         </th>
                              <th data-options="field:'partyD',align:'left',width:'200px' ">
                           丁方
                         </th>
                        <th data-options="field:'signedTime',width:'100px' ">
                            签订时间
                        </th>
                        <th data-options="field:'signedPlace',align:'center',width:'100px' ">
                            签订地点
                        </th>
                           <th data-options="field:'validity',align:'center',width:'100px' ">
                            合同有效期
                        </th>
                    </tr>
                </thead>
                  
            </table>

      <input type="radio" name="unReviewRadio" value="" onclick="checkUnReview(this)" />未审核
       <input type="radio" name="ReviewRadio" value="" onclick="checkReview(this)"/>已审核

posted @ 2017-02-27 15:02  lbja2  阅读(6965)  评论(0编辑  收藏  举报