Multiple selection passed to server action

Multiple selection passed to server action

Oleg2024Oleg2024 Posts: 1Questions: 1Answers: 0

I just started with this component. Your examples are missing a pretty common use-case: Create a table with multiple selection checkboxes, and a button to trigger following action: Get ID filed of all selected rows, create comma-separated string from them called “selection” and pass it as a parameter - redirect to some server action. Can you please create such an example?

Answers

  • allanallan Posts: 63,434Questions: 1Answers: 10,458 Site admin

    Client-side, it is fairly trivial - use rows().ids() with a selector to get only the selected rows (assuming you are using the Select extension for DataTables:

    var ids = myTable.rows({selected: true}).ids();
    
    var idsString = ids.toArray().join(',');
    

    Then you can send to the server to do whatever you want with it.

    If you don't have an id property for the table (rowId), then you can get any data point you want from a row using the pluck() method:

    var ids = myTable.rows({selected: true}).data().pluck('id');
    

    You may wish to do this in a custom button, if you are already using the Buttons extension, but equally, you can use any event you want on the page to do that.

    Allan

Sign In or Register to comment.