PDA

View Full Version : help ! selectRows or selectRecords of CheckboxSelectModel doesn't work



BlazeCrystal
27 Feb 2011, 8:58 PM
i create an ext grid with a self-made page bar. and i want to realize such case:
when i select one record on first page, then jump to the next page, and again, jump to the first page. i need the record is still in selected state.
i used an array to record the records i have selected, and invoked sm.selectRecords(array, true) (sm is CheckboxSelectModel instance), but when i back to the first page , no records selected....:-/
waiting on line , 3Q very much

the below is my code:


Ext.BLANK_IMAGE_URL = '../images/default/s.gif';
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var alreadySelected = new Array();
function showTable() {
var singleSelectValue = false;
if (selectType.toLowerCase() == "radio") {
singleSelectValue = true;
}
var sm = new Ext.grid.CheckboxSelectionModel({
singleSelect : singleSelectValue
});
var colOffset = 0;
var colArray = labels.split(",");
var attrArray = attrs.split(",");
var cmArray = new Array();
var sortColumns = "name,address";

if (selectType != null) {
cmArray[colOffset++] = sm;
}
if (showNo) {
cmArray[colOffset++] = {
header : '\u5e8f\u53f7',
renderer : function(value, metaData, record, rowIndex, colIndex, store) {
return new Number(emt_pageSize.value).valueOf() * (new Number(emt_currentPageNo.value).valueOf() - 1) + rowIndex + 1;
}
};
}
for (var i = 0; i < colArray.length; i++) {
if (colArray[i].trim().indexOf("@") == 0) {
var col = colArray[i].trim().substring(1);
cmArray[colOffset++] = {
header : col,
dataIndex : attrArray[i].trim(),
sortable : true,
hidden : true
};
} else {
var col = colArray[i].trim();
cmArray[colOffset++] = {
header : col,
dataIndex : attrArray[i].trim(),
sortable : true,
hidden : false
};
}
}

var cm = new Ext.grid.ColumnModel(cmArray);
/* var cm = new Ext.grid.ColumnModel([
sm,
{header:'no'},
{header:'name', dataIndex:'name', sortable:true},
{header:'sex', dataIndex:'sex', sortable:true},
{header:'address', dataIndex:'address', sortable:true}
]);*/

var formEmt = document.getElementsByName(formName)[0];

var conn = new Ext.data.Connection({

});

var valueArray = new Array();
for (var i = 0; i < colArray.length; i++) {
var val = attrArray[i].trim();
valueArray[i] = {
name : val
};
}

var ds = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : formEmt.action,
method : "post",
form : formEmt,
success : function(resp, opt) {refreshPageInfo(eval('(' + resp.responseText + ')').page);},
failure : function(resp, opt) {alert("\u5bf9\u4e0d\u8d77\uff0c\u65e0\u6cd5\u8fde\u63a5\u5230\u670d\u52a1\u5668\u6216\u670d\u52a1\u5668\u5fd9\uff0c\u8bf7\u7a0d\u5019\u518d\u8bd5\u6216\u8054\u7cfb\u7ba1\u7406\u5458\u2026\u2026")}
}),
reader : new Ext.data.JsonReader({
totalProperty : 'totalProperty',
root : 'root'
}, valueArray),
remoteSort : true
});

var emtDiv = Ext.get("div_table");
var emtKeyAttrDiv = document.getElementById("div_keyAttr");
var keyArray = keyAttrs.split(",");

var hiddenSelections = document.getElementById("ext_selections");
sm.on("rowselect", function(model, index, rec) {
recordSelectAction(model, keyArray, emtKeyAttrDiv);
alreadySelected[alreadySelected.length] = rec;
});

sm.on("rowdeselect", function(model, index, rec) {
recordSelectAction(model, keyArray, emtKeyAttrDiv);
var tmp = new Array();
for (var i = 0; i < alreadySelected.length; i++) {
if (alreadySelected[i].id != rec.id) {
tmp[tmp.length] = alreadySelected[i];
}
}
alreadySelected = tmp;
});

var grid = new Ext.grid.GridPanel({
el : 'div_table',
ds : ds,
cm : cm,
sm : sm,
viewConfig : {
emptyText : "\u5bf9\u4e0d\u8d77\uff0c\u6682\u65e0\u53ef\u5339\u914d\u6570\u636e\u2026\u2026",
autoFill : true,
forceFit : true
},
stateId : 'paged_table_viewer',
stateful : true,
stripeRows: true,
//autoExpandColumn: "name",
//autoHeight: true,
height:emtDiv.getComputedHeight(),
width:emtDiv.getComputedWidth(),
title: "page table example",
loadMask:{msg:"\u6b63\u5728\u67e5\u8be2\uff0c\u8bf7\u7a0d\u5019\u2026\u2026"}
});
grid.render();
ds.load();
sm.selectRows(alreadySelected);
}


and page jump action is below:


function jumpToAction(obj, keyEvent) {
if (new Number(obj.value).valueOf() > new Number(emt_totalPages.value).valueOf()) {
obj.value = emt_totalPages.value;
}
var eventKeyCode = null;
if (window.event) {
eventKeyCode = keyEvent.keyCode;
} else if (pressEvent.which) {
eventKeyCode = keyEvent.which;
} else {
alert("current navigator doesn't support this action, please use ie/ff/ns/op");
}
if (eventKeyCode == 13) {
emt_currentPageNo.value = obj.value;
showTable();
}
}

tobiu
28 Feb 2011, 12:57 AM
Community Discussion
Open discussion about events, meetups and other general topics of interest to the Sencha Community.


so, we don't even know what framework you are using (ext 1, 2, 3, 4, gwt).
please search the fitting help-forum.


best regards
tobiu

BlazeCrystal
28 Feb 2011, 1:38 AM
i've found the cause.
but still thanks a lot;)