$.fn.extend( memberList ,{
quickSearch : function() {
var time1 = new Date();
/* this.datagrid.datagrid('clearSelections'); */
if(this.advSearchForm) {
this.searchForm.setBaseConditions(this.advSearchForm.getConditions());
}
if( this.beforeSearch(this.searchForm.getQo()) ){
/* this.datagrid.datagrid('clearSelections'); */
this.datagrid.datagrid('load', {
searchConditions : JSON.stringify(this.searchForm.getQo()),
sort : this.sortFields,
order : this.sortRules
});
//initFooter(this,config);
}
var time2 = new Date();
}
});
具体代码:
$("#maingrid").datagrid({
onSelect:function(index,row){
addItem(row.memberId);
},
onUnselect:function(index,row){
removeItem(row.memberId)
},
onSelectAll:function(rows){
addAll(rows);
},
onUnselectAll:function(rows){
removeAll(rows);
},
onLoadSuccess: function(){
if(!ids){
return;
}
var myrows = $('#maingrid').datagrid('getRows');
for(var i=0; i<myrows.length; i++){
for(var j=0; j<ids.length; j++){
if(myrows[i].memberId == ids[j]){
var index = $('#maingrid').datagrid('getRowIndex',myrows[i]);
$('#maingrid').datagrid('selectRow',index);
}
}
}
}
});
function addItem(assetsId){
var arrs = ids.join();
console.info("arrs="+arrs);
if(arrs.indexOf(assetsId) == -1){
ids.push(assetsId);
}
console.info("ids="+ids);
}
//add current page
function addAll(rows){
for(var i=0; i<rows.length; i++){
var arrs = ids.join();
if(arrs.indexOf(rows[i].assetsId) == -1){
ids.push(rows[i].assetsId);
}
}
console.info("addAll-ids="+ids);
}
//remove unSelect
function removeItem(assetsId){
var arrs = ids.join();
console.info("arrs="+arrs);
var indexTmp = arrs.indexOf(assetsId);
console.info("index="+indexTmp);
if(indexTmp != -1){
for(var i=0; i<ids.length; i++){
if(ids[i] == assetsId){
ids.splice(i,1);
}
}
}
console.info("ids="+ids);
}
//remove current page
function removeAll(rows){
for(var i=0; i<rows.length; i++){
var arrs = ids.join();
var indexTmp = arrs.indexOf(rows[i].assetsId);
if(indexTmp != -1){
for(var j=0; j<ids.length; j++){
if(ids[j] == rows[i].assetsId){
ids.splice(j,1);
}
}
}
}
console.info("removeAll-ids="+ids);
}
$("#btn_ok").click(
function(){
var ids = [];
var names=[];
var rows = $('#maingrid').datagrid('getSelections');
for(var i=0; i<rows.length; i++){
ids.push(rows[i].memberId);
names.push(rows[i].trueName);
}
$("#recList").val(ids.join());
$("#member_win").dialog("close");
$("#recListName").textbox("setValue",names.join());
});