Author Topic: Getting a list of all checked rows  (Read 4934 times)

webifi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 45
    • View Profile
Getting a list of all checked rows
« on: April 09, 2015, 07:29:06 pm »
I have a grid with a checkBoxSelection column.

What is the recommended way of returning an array of rows that have been checked?  Further, how does one return an array of rows that have been checked, and are currently visible via any applied filter? (Exclude rows that are not visible due to filtering.)

I tried using beforeCheck/beforeunCheck to add/remove classes to rows, coupled with getRowsByClass, but beforeCheck/beforeunCheck is not triggered when using the check all/uncheck all checkbox in the column header, making beforeCheck/beforeunCheck somewhat crippled.  selection({method:'getSelection', type:row}) only seems to return the last row that was checked.

« Last Edit: April 09, 2015, 08:34:13 pm by webifi »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Getting a list of all checked rows
« Reply #1 on: April 09, 2015, 09:49:58 pm »
getSelection is used to get the selected rows. It returns selected rows even after applying filter.

selected rows can be same or not as checked rows depending upon whether you use checkboxes for selecting rows. In former case getSelection can be used to get checked rows but in later case you have to iterate over the dataModel.data and get the rows where ( rowData['dataIndx of checkbox'] === true. )

I don't see any issue with beforeCheck/ beforeunCheck w.r.t the header checkbox. Please share a jsfiddle where the issue can be seen.
« Last Edit: April 09, 2015, 09:54:22 pm by paramquery »

webifi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Getting a list of all checked rows
« Reply #2 on: April 09, 2015, 09:57:41 pm »
So, after some experimentation, it looks like you must use selectionModel type:null with the checkBoxSelection column.  Unfortunate.  There is no way to combine checkBoxSelect with inline editing to allow for easy "delete checked rows" functionality -- looks like I'd need to roll my own using a custom column rendering, etc -- but even then, there doesn't seem to be an easy way to get all visible rows that have a "checked" column.

I'll set up a jsfiddle demonstrating the before/beforeunCheck header checkbox issue when I have time.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Getting a list of all checked rows
« Reply #3 on: April 09, 2015, 10:33:43 pm »
It's not that difficult as it may have sound, it's only a matter of writing single for loop to get list of all checked rows as mentioned in my previous post, the same method is applicable even if you apply filter.

var checked = [];
for (var i = 0, len = data.length; i < len; i++) {
        var rowData = data;
        if (rowData.state) {
             checked.push(rowData.id);
        }
}

Please check this demo to get list of checked rows, along with filtering:

http://paramquery.com/pro/demos/checkbox_id

webifi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: Getting a list of all checked rows
« Reply #4 on: April 10, 2015, 12:23:09 am »
Thanks.
« Last Edit: April 10, 2015, 12:24:43 am by webifi »