PDA

View Full Version : Ext.grid.CheckboxSelectionModel check or uncheck in run time



saravanant
8 Sep 2009, 7:48 AM
Hi

I have a grid with the Ext.grid.CheckboxSelectionModel. I want to check this checkBox column based on the some validation. I am trying with the following code. But this check box column is not getting checked in run time. Can you please help me to resolve this check box issue




var sm =new Ext.grid.CheckboxSelectionModel({
singleSelect:false,
dataIndex:'CheckBoxValue'
});



var purchOrdersColModel = new Ext.grid.ColumnModel([

{id:OID_UI,header: "Order ID In", width: 80, sortable: true, locked:false, dataIndex:OID_UI, hidden:true},
{header: "uiOrderNumber", width: 80, sortable: true, locked:false, dataIndex:'uiOrderNumber', hidden:true},
{header: "status" ,width:100,sortable:true,dataIndex:UI_PO_STATUS,hidden:true},
{header: "Type", width:60, sortable: false, locked:false, dataIndex: 'ORDER_TYPE'},
{header: "Order ID", width: 80, sortable: true,defaultSortable:true, locked:false, dataIndex:'ORDER_NO'},
{header: "Style No", width: 80, sortable: true, locked:false, dataIndex: 'STYLE'},
{header: "Style Desc", width: 95, sortable: true, locked:false, dataIndex: 'STYLE_DESC',css:'buttonCss'},
{header: "Supp", width: 80, sortable: true, locked:false, dataIndex: 'SUPPLIER_NAME'},
{header: "Colour", width: 65, sortable: true, locked:false, dataIndex: 'COLOUR_NAME'},
{header: "RP ID", width: 65, sortable: true, locked:false, dataIndex: 'PACK_NO'},
{header: "RP/Singles", width: 95, sortable: true, locked:false, dataIndex: 'RP_SINGLES'},
{header: "Total Qty", width: 82, sortable: true, dataIndex: 'QUANTITY'},
{header: "Del Date", width: 85, sortable: true, renderer:formatDate, dataIndex: 'DELIVERY_DATE'},
{id:'supStatusId',header: "Supp/Del", width: 65, sortable: false, hidden:true,dataIndex: 'SuplierDeliveryStatus'
,renderer:function(value, metaData, record, rowIndex, colIndex, store) {
if (value == 'Pending') {
metaData.css = 'pendingCls';
}else if (value == 'Complete'){
metaData.css = 'completeCls';
}
return value;
}},
{id:'ProductStatusId',header: "Products", width: 65, sortable: false, hidden:true,dataIndex: 'ProductStatus',renderer:function(value, metaData, record, rowIndex, colIndex, store) {
if (value == 'Pending') {
metaData.css = 'pendingCls';
}else if (value == 'Complete'){
metaData.css = 'completeCls';
}
return value;
}},
{id:'CostingsStatusId',header: "Costings", width: 65, sortable: false,hidden:true,dataIndex: 'CostingsStatus',renderer:function(value, metaData, record, rowIndex, colIndex, store) {
if (value == 'Pending') {
metaData.css = 'pendingCls';
}else if (value == 'Complete'){
metaData.css = 'completeCls';
}
return value;
}},
{header:"", width:14, sortable: true,dataIndex: ''},
{id:'status2',header: "Status", width: 60, sortable: false, dataIndex: 'Status2',css:'test'},
{header:"", width:14, sortable: true,dataIndex: ''}, sm

]);







purchaseOrdersTable = Ext.data.Record.create([
{name : ACTION},
{name : VERSION},
{name : ORDERNO,type:'int',sortDir: 'DESC', sortType: 'asInt'},
{name : OID_UI},
{name : TECH_LIST_ID},
{name : STATUS},
{name : 'STATUS'},
{name : 'Status2'},
{name : UI_PO_STATUS},
//
{name : MRKGRPID},
{name : MRKGRPNAME_UI},
{name : DEPARTMENTID},
{name : DEPARTMENTNAME_UI},
{name : STYLENR},
{name : STYLENO},
{name : STYLEDESC_UI},
{name : STYLE_ACTION},
{name : SIZEGRPID},
{name : SIZEGRPNNAME_UI},
{name : ORDERTYPEID},
{name : ORDERTYPE_UI},
{name : BARCODEREQ},
{name : COMMENTS},
{name : MAIN_ACTION},
//
{name : SUPPLIERID},
{name : SUPPLIERNAME_UI},
{name : SUPPLIER_VPN},
{name : COUNTRYOFORIGID},
{name : COUNTRYOFORIGNAME_UI},
{name : ADDRESSID},
{name : ADDRESS_UI},
{name : SUPPLIER_ACTION},
//
{name : TOTALPACKS},
{name : PACKINGMETHOD},
{name : PACKINGMETHOD_UI},
{name : RATIOPACK},
{name : PRODUCT_ACTION},
{name : TOATLQUANTITY_UI},
//

{name : ORIGINCITY},
{name : ORIGINCITYID},
{name : FREIGHTMETHID},
{name : FREIGHTMETHNAME_UI},
{name : LADINGPORTID},
{name : LADINGPORTNAME_UI},
{name : DISCHARGEPORTID},
{name : DISCHARGEPORTNAME_UI},
{name : WAREHAUSEID},
{name : WAREHAUSENAME_UI},
{name : CROSSDOCKED},
{name : DELIVERYTYPE},
{name : FOBDATE,type: 'date', dateFormat: uiDateFormat},
{name : DELIVERYDATE ,type: 'date', dateFormat: uiDateFormat},
{name : DELIVERYDATE_UI,type: 'date', dateFormat: uiDateFormat},
{name : DELIVERY_ACTION},
{name : RANGEPERIODID}, //added by Shibu for Range Periods
//{name : RANGEPERIOD_UI}, //added by Shibu for Range Periods
//COSTINGS_ACTION
{name : COSTINGS_STATUS},
{name : COSTINGS_ACTION},
{name : UKRETAIL},
{name : EIRRETAIL},
{name : SUPP_COTS_DIR_CC},
{name : EXCHANGERATE},
{name : CURRENCYCODE},
{name : HTSCODE},
{name : VAT},

{name : TOTAL_ORDER_COST},
{name : LANDEDCOST},
{name : TOTAL_ORDER_RETAIL},
{name : MARGIN},

{name : UNIT_COST_PRICE},
{name : PROCESSING_CODE},
{name : PROCESSING_RATE},
{name : HANGER_CODE},
{name : HANGER_RATE},
{name : COMMISSION},
{name : COMMISSION_RATE},
{name : ANTI_DUMPING_DUTY},
{name : ANTI_DUMPING_RATE},
{name : LOGROYALITY},
{name : DESIGNROYALITY},
{name : STORAGE},
{name : COLOUR_NAME},
{name : COLOUR_ACTION},
{name : SIZE_ACTION},
{name : AMEND},
{name : 'locked'},
{name : 'CheckBoxValue'}
]);






var orderTableGrid = new Ext.grid.GridPanel({
store: PoSearchStore,
cm: purchOrdersColModel,
sm: new Ext.grid.CheckboxSelectionModel({singleSelect:false,
listeners:{
beforerowselect:function(sm, rowIndex, keep, rec){
if(rec.data.locked!=undefined){
return false;
}
}
}}),
width:920,
buttons: [recordsRetrievedLabel,first_but,prev_but,currentSearchPage,totalPagesPanel,next_but,last_but],
region: 'south',
height: orderListSectionTablePanelH,
enableColumnHide: false
});




PoSearchStore = new Ext.data.Store({
sortInfo:{field:'ORDER_NO', direction: "DESC"},
reader: purchaseOrdersJsonReader1
});

var purchaseOrdersJsonReader1 = new Ext.data.ArrayReader({
},orderSearchTable);





orderSearchTable = Ext.data.Record.create([
{name:'ORDER_NO',type:'int',sortDir: 'DESC', sortType: 'asInt'},
{name:'ORDER_TYPE'},
{name:'ORDER_TYPE_ID'}, //added by Shibu for AHNLT-810
{name:'STYLE'},
{name:'STYLE_DESC'},
{name:'COLOUR_NAME'},
{name:'RP_SINGLES'},
{name: 'SUPPLIER_NAME'},
{name: 'QUANTITY'},
{name: 'DELIVERY_DATE'},
{name: 'CheckBoxValue'}
])


Here i am trying to set the checkbox value to true while creating the new record but check box is not checked.



var record = new purchaseOrdersTable(order);
var deliveryDate = record.get('DELIVERY_DATE');
var dt = Date.parseDate(deliveryDate,rmsSearchDateFormat);
var deliveryDateUi = dt.format(uiDateFormat);
record.data['DELIVERY_DATE'] = deliveryDateUi;
var orderNum = record.get('ORDER_NO');
var orderNumInt = parseInt(orderNum,10);
record.data['ORDER_NO']=orderNumInt;
record.data['SuplierDeliveryStatus']='Complete';
record.data['ProductStatus']='Complete';
record.data['CostingsStatus']='Complete';
if(record.get('STATUS') == 'W')
{
record.data['Status2'] = 'WorkSheet';
}else if(record.get('STATUS') == 'A'){
record.data['Status2'] = 'Approved';
}else if(record.get('STATUS') == 'S'){
record.data['Status2'] = 'Submitted';
}else if(record.get('STATUS') == 'C'){
record.data['Status2'] = 'Closed';
}else{
record.data['Status2']=record.get('STATUS');

}
record.data['locked']=record.get('LP_FLAG');
if(record.get('LP_FLAG')!=undefined){
lockPartRecFlag = 1;
if(record.get('LP_FLAG')=='L'){
record.data['Status2'] = 'Locked';
}else if(record.get('LP_FLAG')=='R'){
record.data['Status2'] = 'Part Received';
}
}
record.data['CheckBoxValue'] = true;

if(record.get('STATUS') == 'C'){
purchaseOrdersStore.remove(record);
}else{
PoSearchStore.add(record);
}


PoSearchStore.filterBy(filterByBlankColors);
PoSearchStore.commitChanges();

Jack9
8 Sep 2009, 8:38 AM
var myCBSM = new Ext.grid.CheckboxSelectionModel({
singleSelect:false,
listeners:{
beforerowselect:function(sm, rowIndex, keep, rec){
if(rec.data.locked!=undefined){
return false;
}
}
}
});

var orderTableGrid = new Ext.grid.GridPanel({
store: PoSearchStore,
cm: purchOrdersColModel,
sm: myCBSM,
width:920,
buttons: [recordsRetrievedLabel,first_but,prev_but,currentSearchPage,totalPagesPanel,next_but,last_but],
region: 'south',
height: orderListSectionTablePanelH,
enableColumnHide: false
});

orderTableGrid.getSelectionModel().selectRow(4,true);
// myCBSM.selectRow(4,true);
The selection model is the only thing that knows what is "checked". Not sure where that's ever explained, I had to learn by trial and error.

saravanant
8 Sep 2009, 10:42 PM
thanks for the solution. its working now after implementing the below line.

orderTableGrid.getSelectionModel().selectRow(recordsCount,true)

Cheers
Saravanan

saravanant
9 Sep 2009, 4:00 AM
i am trying to stop selecting the row when selecting a row based on particular condition.
Can you help me how to stop selecting the row when selecting it.


var orderTableGrid = new Ext.grid.GridPanel({
store: PoSearchStore,
cm: purchOrdersColModel,
sm: new Ext.grid.CheckboxSelectionModel({singleSelect:false,
listeners:{
beforerowselect:function(sm, rowIndex, keep, rec){
var selectedOrders = this.getSelections();
if( selectedOrders.length > 0){
if(rec.data.Status2!=selectedOrders[0].data.Status2){
alert("Please select same status orders");
alert("Dont select this record");
this.fireEvent('rowdeselect', this, rowIndex, rec);
}
}
if(rec.data.locked!=undefined){
return false;
}
}
}}),
width:920,
buttons: [recordsRetrievedLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,emptyLabel,first_but,prev_but,currentSearchPage,totalPagesPanel,next_but,last_but],
region: 'south',
height: orderListSectionTablePanelH,
enableColumnHide: false
});