Select rows for all pages in a search subset

Select rows for all pages in a search subset

dynasoftdynasoft Posts: 446Questions: 69Answers: 3

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: Hi, I have an issue where I set a button to select all rows using table.rows( { page: 'all' } ).select();. But if I do a search for say 40 out of 100 results, and hit that button and check how many rows are selected using dataTable1.rows({ selected: true }).data(); it returns all 100 rows, not just the 40. The correct subset of 40 rows seems to be selected on all pages when I navigate through the pages after I hit the selectall button. Please advise if there is another parameter apart from page: 'all' and page: 'current' that only selects the rows in pages displayed.

This question has an accepted answers - jump to answer

Answers

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    I'm reading data from the DOM

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3
    edited June 2020

    I'm trying to progress with this and trying to iterate through the rows shown after a search and trying to select them:

                buttons: [
                    { extend: 'create', editor: editor1 },
                    { extend: 'edit', editor: editor1 },
                    { extend: 'remove', editor: editor1 },
                    {
                        text: '@(lblo.lblSelectAll)',
                        action: function (e, dt, node, config) {
                            var table = $('#tblDataTable1').DataTable();
                            var objRows = table.rows( {order:'index', search:'applied'} ).nodes();
                            if (objRows.length > 0) {
                                //for(var i = 0; i < objRows.length; ++i){
                                //    objRows[i].addClass('selected');
                                //}
                                objRows.select().draw();
                            }
                            else {
                                table.rows( { page: 'all' } ).select();
                            }
                            objRows = null;
                            table = null;
                        }
                    },
    

    objRows holds the rows from the search results but next is to select them in code. I can't find how this is done: how would i iterate through the objRows object or 'bulk' select them directly via some .select() method? Many thanks.

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    Use the selector-modifier of { search: 'applied' }, for example:
    table.rows( {search: 'applied'} ).select();

    Here is a running example:
    http://live.datatables.net/rowidovi/1/edit

    Is this what you are looking for?

    Kevin

  • dynasoftdynasoft Posts: 446Questions: 69Answers: 3

    Many thanks. Will try this.

This discussion has been closed.