Ext4.2 gird 批量删除,最后一页全删了查询上一页

 

//查询
function getPageList(pageIndex){
	if(typeof(pageIndex) == "undefined"){
		pageIndex = 1;
	}
	//stoOrganization.currentPage=1; //解决查询后分页栏(pagingtoolbar)显示的不是第一页的问题
	stoOrganization.pageSize = pagesize_combo.getValue();
	//stoOrganization.load({params: { start: 0, limit: pagesize_combo.getValue() }});
	stoOrganization.loadPage(pageIndex,{params: { start: (pageIndex-1)*stoOrganization.pageSize, limit: pagesize_combo.getValue()}});
}

  

//删除
function remove(){
	gridRemove(gridOrganization,stoOrganization,'id','remove.json','POST',function(response, opts, pageIndex){
		refreshNode(treOrganization, false, currentNodeId, parentNodeId);
		getPageList(pageIndex);
		gridOrganization.getSelectionModel().deselectAll();
	});
}

 

/**
 * 返回grid表格复选框选中的ids
 * @param records	选中的记录
 * @param id		id列的名字
 * @returns			1,2,3
 */
function getIds(records,id){
	var ids = [];
	for (var i = 0; i < records.length; i++) {
		ids.push(records[i].get(id));
	}
	return ids.toString();
}

 

/**
 * 删除
 * @param grid		grid对象
 * @param store		sotre对象
 * @param id		id列的名字
 * @param url		删除请求url
 * @param method	提交方式GET/POST
 */
function gridRemove(grid,store,id,url,method,callback){

	//var pageCount = grid.getDockedItems('toolbar[dock="bottom"]')[0].getPageData().pageCount;

	var isLastPage = false;	//是否是最后一页
    if(!(store.last()) || store.indexOfTotal(store.last()) == store.getTotalCount()-1){
    	isLastPage = true;
    }

	var records = grid.getSelectionModel().getSelection();
	if(records.length == 0){
		Ext.Msg.alert("提示", "请先选择数据行!");
		return;
	}
	
	var ids = getIds(records, id);
	
    Ext.Msg.confirm("警告", "确定要删除吗?", function (button) {
        if (button == "yes") {
            Ext.Ajax.request({
        	    url: url,
        	    method: method,
        	    params: {
        	        ids: ids
        	    },
        	    success: function(response, opts) {
        	        var json = Ext.decode(response.responseText);
        	        if(json.status == "success"){
        	        	//store.reload();
        	        	Ext.Msg.alert('提示', "删除成功!");
        	        	
        	        	//是最后一页,并且全删了,查询上一页的
        	        	if(isLastPage && store.getCount() == records.length){
        	        		if(store.currentPage > 1){
        	        			store.currentPage = store.currentPage - 1;
        	        		}
        	        	}
        	        	
        	        	if(typeof(callback) == 'function'){
        	        		callback(response, opts, store.currentPage);
        	        	} else {
        	        		store.reload();
        	        	}
        	        } else {
        	        	Ext.Msg.alert('提示', json.msg);
        	        }
        	        
        	    },
        	    failure: function(response, opts) {
        	    	Ext.Msg.alert('提示', '数据删除失败!'); //response.status
        	    }
            });
        }
    });
}

 

你可能感兴趣的:(删除,ext,grid)