ExtJS found 05_grid to get the checkbox Value

Source: Internet
Author: User
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
},
...
]
);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.