datagrid记忆翻页前后的勾选项

定义一个变量存储所选项:

var selRows = [];

选择一行数据的时候:

onCheck:function(index,row){
            if(selRows.length == 0){
                selRows.push(row);
            } else {
                var has = false;
                for(var i = 0; i < selRows.length; i++){
                    if(row.customerId == selRows[i].customerId && row.if20 == selRows[i].if20){
                        has = true;
                        break;
                    }
                }
                if(has == false){
                    selRows.push(row);
                }
            }
 }

去掉一行勾选项的时候:

onUncheck:function(index,row){
            for(var i = 0; i < selRows.length; i++){
                if(row.customerId == selRows[i].customerId && row.if20 == selRows[i].if20){
                    selRows.splice(i,1);
                    break;
                }
            }
 }

选择勾选当页所有数据的时候:

onCheckAll:function(rows){
            if(rows && rows.length > 0){
                for(var j = 0; j < rows.length; j++){
                    var row = rows[j];
                    var has = false;
                    for(var i = 0; i < selRows.length; i++){
                        if(row.customerId == selRows[i].customerId && row.if20 == selRows[i].if20){
                            has = true;
                            break;
                        }
                     }
                    
                    if(has == false){
                        selRows.push(row);
                    }
                }
            }
   }

去掉勾选当页所有数据的时候:

onUncheckAll:function(rows){
            if(rows && rows.length > 0){
                for(var i = 0; i < selRows.length; i++){
                    for(var j = 0; j < rows.length; j++){
                        if(rows[j].customerId == selRows[i].customerId && rows[j].if20 == selRows[i].if20){
                            selRows.splice(i,1);
                            i--;
                            break;
                        }
                    }
                }
            }  
}

刷新列表的时候反选;

onLoadSuccess:function(row){
            if(selRows && selRows.length > 0){
                var rows = row.rows;
                for(var i = 0; i < selRows.length; i++){
                    for(var k =0 ;k < rows.length; k++){
                        if(rows[k].customerId == selRows[i].customerId && rows[k].if20 == selRows[i].if20){
                            $('#developTree').datagrid('checkRow', k);
                            break;
                        }
                    }
                }
            }

}

猜你喜欢

转载自blog.csdn.net/HouJi1/article/details/83651731