easyui分页全选(前端分页)

 var select_Arr = [];//选中数据
 var selectAll = [];//全部数据
$("#tplList").datagrid({
            idField: 'id',
            fit: false,
            pagination: true,
            toolbar: "#templateSearch",
            fitColumns: true,
            autoRowHeight: true,
            rownumbers: false,
            checkOnSelect:false,
            url: "showListByParam.json",
            singleSelect: false,
            loadFilter:function(data){//这里是重点
                if (typeof data.length == 'number' && typeof data.splice == 'function') {   // is array
                    data = {
                        total: data.length,
                        rows: data
                    }
                }
                var dg = $(this);
                var opts = dg.datagrid('options');
                var pager = dg.datagrid('getPager');
                pager.pagination({
                    onSelectPage: function (pageNum, pageSize) {
                        opts.pageNumber = pageNum;
                        opts.pageSize = pageSize;
                        pager.pagination('refresh', {
                            pageNumber: pageNum,
                            pageSize: pageSize
                        });
                        dg.datagrid('loadData', data);
                    }
                });
                if (!data.originalRows) {
                    data.originalRows = (data.rows);
                }
                var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
                var end = start + parseInt(opts.pageSize);
                data.rows = (data.originalRows.slice(start, end));
                selectAll=data.originalRows;
                if(select_Arr){
                    $.each(select_Arr,function(i,n){
                        $.each(data.rows,function(j,v){
                            if(n.id == v.id ){
                                // if(v.status != 0){
                                    v['checked'] = true;
                                // }
                            }
                        });
                    });
                }
                // $('#tplList').datagrid('unselectRow',index);
                return data;
            },
            onCheckAll:function (data) {
                for(var i =0;i// if(selectAll[i].status != 0){
                        select_Arr.push(selectAll[i]);
                    // }
                }
                // for(var i =0;i
                //     if(selectAll[i].status == 0){
                //         $('#tplList').datagrid('uncheckRow',i);
                //     }
                // }
            },
            onCheck:function(index,row){
                if(row.status == 0 || row.publishStatus != 1){
                    $('#tplList').datagrid('uncheckRow',index);
                }
            },
            onUncheckAll:function () {
                select_Arr=[];
                // selectAll=null;
                // $('#tplList').datagrid("clearSelections");
            },
            onSelect:function (index,row) {
                    $.each(select_Arr,function(i,n){
                            if(n.id != row.id){
                                select_Arr.push(row.id);
                            }
                    });
                    if(row.status == 0 || row.publishStatus != 1){
                        $('#tplList').datagrid('unselectRow',index);
                    }
            },
            onUnselect:function (index,row) {
                for(var i in select_Arr){
                    if(select_Arr[i].id == row.id){
                        // delete select_Arr[i]
                        select_Arr.splice(i,1);
                    }
                }
            },
        });

你可能感兴趣的:(前端)