说明:勾选某几条记录后,翻页再翻回来,保持原来的选中状态。
原理:在勾选或取消勾选的时候用recordIds保存或删除勾选中的Record的主键id值,
每次store加载(load事件)完后,遍历store,比较每条Record的主键列id是否在recordIds中,
若存在则将Record保存到临时变量records中,最后调用selMod.selectRecords(records, true);
写Array的remove与contains方法,搞得有点像java.util.HashSet(不让Array存重复值)
Js代码
1. function
2. for(var
3. if(array[i]!=attachId){
4. array[n++]=array[i]
5. }
6. }
7. array.length -= 1;
8. }
9. function
10. for(var
11. if(array[i]==attachId){
12. return true;
13. break;
14. }
15. }
16. return false;
17. }
18. Array.prototype.remove = function
19. return RemoveArray(this,obj);
20. };
21. Array.prototype.contains = function
22. return containsArray(this,obj);
23. };
Js代码
1. var recordIds=new Array();// 选中的Record主键列id列表
2. var recordsChecked=new Array();// 选中的Record列表
3.
4. var store = new
5. 'viewXXX.do',
6. true,
7. 'totalProperty',
8. 'root',
9. 'id'},
10. 'status'}
11. ],
12. listeners : {
13. function() {
14. var records = new
15. function(record) {
16. if
17. records.push(record);
18. });
19. true);// 以后每次load数据时,都会默认选中
20. }
21. }
22. });
23.
24. var selMod = new
25. handleMouseDown : Ext.emptyFn,
26. listeners : {
27. "rowdeselect"
28. function(e, rowIndex, record) {
29. if
30. recordIds.remove(record.data.id);
31. recordsChecked.remove(record);
32. }
33. }
34. },
35. "rowselect"
36. function(e, rowIndex, record) {
37. if
38. recordIds.push(record.data.id);
39. recordsChecked.push(record);
40. }
41. }
42. }
43. });