PDA

View Full Version : How to check if a grid row (any row) is selected??



JohnJones357
20 Mar 2014, 11:57 AM
Not which row is selected, but if any row in general is selected. I have a delete button on grid tbar which uses SelectionModel(). But in the event user launches grid and clicks delete button, this will throw an error since no record(row) is selected. So maybe I can check to see if a row is selected and only then enable the delete button or something. Normally would be no biggie but this will be going in to testing phase soon.

Need a quick response, thanks!

droessner
20 Mar 2014, 1:01 PM
You can add a selectionchange listener to your grid and then set the button to be enabled/disabled based on the selections in the grid. The second parameter will be an array of all the selected records.

See http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.Panel-event-selectionchange

usavahe
20 Mar 2014, 1:10 PM
ON your question "So maybe I can check to see if a row is selected and only then enable the delete button or something."You can check of there is a selection my doing the following:

var checkedRows = yourgrid.getSelectionModel().getSelection();
if (checkedRows.length > 0) button.enable;
// ...

JohnJones357
20 Mar 2014, 1:24 PM
both examples worked great! i knew it was an easy solution but just could not seem to get it right. I chose the 2nd way because its more simple and clean. thanks again for quick replies!