jqgrid select checkbox
Asked Answered
E

1

0

I have a checkboxes on my grid by ways of having the following code:

     colNames: [..., 'Select'],
     ...
     ...

     { name: 'act', index: 'act', width: 30, sortable: false }
     ....

     <input type="button" id="bUpload" value="Upload Report" />

What the user clicks on the Upload button, and the user has multiple checkboxes selected for this column, I like to show a message. I am not sure how to do this.

I tried the following but

     $("#bUpload").click(function() {

       var selectedRow;

       if ($("input:checked").length > 1)
       {
          alert('Error -  Please select only one row.');
          return false;
       }


       if ($("input:checked").length > 0) 
       {              
          $("input:checked").each(function() 
          {
             selectedRow = this.value ;
          });
        }    

....

This works but the reason why I do not like this is because I can have other checkboxes for other columns as well to where there can be confusion as to if they selected from the 'act' column or not. How do I say if the column is for 'act' then check how many were selected.

Eustatius answered 6/2, 2013 at 22:40 Comment(1)
Could you post more implementation details? The current code seems very suspected at least because the checkbox button has id attribute. At the first look the usage of formatter: "checkbox", formatoptions: {disabled: false} would be the best choice for you. You can use additionally beforeSelectRow or onCellSelect to catch checking of the checkboxes.Exhortative
E
0

You could iterate through each row on the grid and test each row.

//iterate over each row 
var rowIds = $('#gridName').jqGrid('getDataIDs');

for (i = 1; i <= rowIds.length; i++) {
    rowData = $('#gridName').jqGrid('getRowData', i);

    if(rowData['act'] //etc..checkbox check) {

    }//if
}//for
Excruciation answered 7/2, 2013 at 0:42 Comment(3)
Thanks but this does not seem to work. Why are we passing i. Shoudn't it be the value of each rowId?Eustatius
I is the number of the row, as you are iterating over each row of the grid. This then lets you check the value of the cell you care about.Excruciation
Where can I use this.Value in order to get the value of what was checked?Eustatius

© 2022 - 2024 — McMap. All rights reserved.