Add checkbox to the front of each column of the grid: (I use the first one, and a string array in the background can be accepted) A general grid uses an Ext. grid. columnModel is enough. To add a multi-choice column, you can add a multi-choice column template Ext. grid. checkboxSel... syntaxHigh
Add checkbox before each column of the grid: (I use the first type, and accept a string array in the background)
A general grid can use an Ext. grid. ColumnModel. To add a multi-choice column, you can add a multi-choice column template Ext. grid. CheckboxSelectionModel:
Var sm = new Ext. grid. CheckboxSelectionModel ();
Var cm = new Ext. grid. ColumnModel (
[
Sm,
{Id: 'company', header: "company", width: 60, sortable: true, dataIndex: 'company '},
]
);
In addition, you must specify this sm as selModel when instantiating EditorGridPanel.
If the selModel of EditorGridPanel is not specified, the checkbox cannot be checked.
Grid = new Ext. grid. rGridPanel (
{
Id: 'editgridtestajax ',
Width: 700,
Height: 500,
El: 'topic-grid ',
Store: ds,
Cm: cm,
ClickToEdit: 2, // double-click to enter the editing status
SelModel: sm // This selModel can be abbreviated as sm
}
);
Get the checkbox Value
Function modfiy (){
If (grid. getSelectionModel (). hasSelection ()){
Var records = grid. getSelectionModel (). getSelections ();
Var mycars = new Array ();
For (var I = 0; I Mycars [I] = records [I]. data. xwbh;
}
Alert (mycars. length );
Return mycars
} Else {
Alert ('select the record for operation! ');
}
};
Function deleteall (){
Var values = modfiy ();
Ext. MessageBox. confirm ("Please confirm", "whether to delete selected information", function (button, text ){
If (button = 'yes '){
Ext. Ajax. request ({
Url: 'news _ query. do ',
Method: 'post ',
Params: {values: values '},
Success: function (req ){
Var responseObj = Ext. util. JSON. decode (req. responseText );
If (responseObj. success = 'true '){
Ext. Msg. alert ("Success prompt", responseObj. infor );
} Else {
Ext. Msg. alert ("error prompt", responseObj. infor );
Return;
}
}
});
} Else {
Return;
}
});
}
// Process the checkbox check event
Grid. getSelectionModel (). on ('rowselect', function (sm, rowIdx, r ){
Alert ('After the checkbox is checked, get the name of the selected row:' + grid. store. getAt (rowIdx). get ('name '));
});
// Process the checkbox uncheck event
Grid. getSelectionModel (). on ('rowselect', function (sm, rowIdx, r ){
Alert ('deselect the checkbox check and name: '+ grid. store. getAt (rowIdx). get ('name') in the obtained record '));
});
Another way is to write a checkbox column in ColumnModel.
Function changeCheck (value, cellmeta, record, rowIndex, columnIndex, store ){
Return"";
}
// The oneclick method above is defined outside Ext. onReady ().
Var cm = new Ext. grid. ColumnModel (
[
{// Custom multi-choice Columns
Header :"",
DataIndex: 'addsid ',
Renderer: changeCheck,
Width: 20,
Sortable: false
},
...
]
);
Add checkbox before each column of the grid: (I use the first type, and accept a string array in the background)
A general grid can use an Ext. grid. ColumnModel. To add a multi-choice column, you can add a multi-choice column template Ext. grid. CheckboxSelectionModel:
Var sm = new Ext. grid. CheckboxSelectionModel ();
Var cm = new Ext. grid. ColumnModel (
[
Sm,
{Id: 'company', header: "company", width: 60, sortable: true, dataIndex: 'company '},
]
);
In addition, you must specify this sm as selModel when instantiating EditorGridPanel.
If the selModel of EditorGridPanel is not specified, the checkbox cannot be checked.
Grid = new Ext. grid. rGridPanel (
{
Id: 'editgridtestajax ',
Width: 700,
Height: 500,
El: 'topic-grid ',
Store: ds,
Cm: cm,
ClickToEdit: 2, // double-click to enter the editing status
SelModel: sm // This selModel can be abbreviated as sm
}
);
Get the checkbox Value
Function modfiy (){
If (grid. getSelectionModel (). hasSelection ()){
Var records = grid. getSelectionModel (). getSelections ();
Var mycars = new Array ();
For (var I = 0; I Mycars [I] = records [I]. data. xwbh;
}
Alert (mycars. length );
Return mycars
} Else {
Alert ('select the record for operation! ');
}
};
Function deleteall (){
Var values = modfiy ();
Ext. MessageBox. confirm ("Please confirm", "whether to delete selected information", function (button, text ){
If (button = 'yes '){
Ext. Ajax. request ({
Url: 'news _ query. do ',
Method: 'post ',
Params: {values: values '},
Success: function (req ){
Var responseObj = Ext. util. JSON. decode (req. responseText );
If (responseObj. success = 'true '){
Ext. Msg. alert ("Success prompt", responseObj. infor );
} Else {
Ext. Msg. alert ("error prompt", responseObj. infor );
Return;
}
}
});
} Else {
Return;
}
});
}
// Process the checkbox check event
Grid. getSelectionModel (). on ('rowselect', function (sm, rowIdx, r ){
Alert ('After the checkbox is checked, get the name of the selected row:' + grid. store. getAt (rowIdx). get ('name '));
});
// Process the checkbox uncheck event
Grid. getSelectionModel (). on ('rowselect', function (sm, rowIdx, r ){
Alert ('deselect the checkbox check and name: '+ grid. store. getAt (rowIdx). get ('name') in the obtained record '));
});
Another way is to write a checkbox column in ColumnModel.
Function changeCheck (value, cellmeta, record, rowIndex, columnIndex, store ){
Return"";
}
// The oneclick method above is defined outside Ext. onReady ().
Var cm = new Ext. grid. ColumnModel (
[
{// Custom multi-choice Columns
Header :"",
DataIndex: 'addsid ',
Renderer: changeCheck,
Width: 20,
Sortable: false
},
...
]
);