How to select all the rows of the current page on server side table?

How to select all the rows of the current page on server side table?

JanurajJanuraj Posts: 85Questions: 18Answers: 0

select all the rows of the current page on server side table

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    If you're using Select extension, you can use rows().select(), something like table.rows({page: 'current'}).select().

    However, that selection will be lost if the page is changed, as when using serverSide only the displayed data is present.

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    I am using Select extension, and getting the error
    Uncaught TypeError: Cannot read property 'style' of undefined
    at r (dataTables.select.min.js

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You normally get that if the number of cells in the header doesn't match the number in the body of the table. If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    @colin It would be helpful if u share any example for this if you have any

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    If you look at the examples, you'll see that - the number of header cells matches the body cells matches the ajax data. The best way to move this forward would be to provide the test case as requested.

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0
    edited November 2020

    @colin since providing the test case would be difficult.
    is there any way to check if i am including select extension in the page?
    and
    can i get the rows only on the current page,so i can explicitly check the checkboxes?

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2020

    is there any way to check if i am including select extension in the page?

    You can use the Datatables debugger.

    can i get the rows only on the current page,

    Look at the rows() API docs and you will see that you can use the selector-modifier to choose which rows to get. There are examples for getting the rows on the page and getting only selected rows. Combine them into one object like this:

    table.rows( {page:'current', selected:true} ).data();
    

    Uncaught TypeError: Cannot read property 'style' of undefined at r (dataTables.select.min.js

    As Colin said, this isn't from getting the row data. You get this error when adding rows to a Datatable. Your data structure doesn't match the table structure. In order to help debug this we will need to see an example of what you are doing. You can use Javascript data for the example.

    Kevin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0

    the value for this "table.rows( {page:'current'} ).data() " is
    Api [{…}, context: Array(1), selector: {…}, tables: ƒ, table: ƒ, draw: ƒ, …]
    but not getting the array of rows

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited November 2020

    table.rows( {page:'current'} ).data() works here:
    http://live.datatables.net/yuqicuni/1/edit

    Please update the test case to show the problem you are having.

    When/where are you using table.rows( {page:'current'} ).data()? Maybe you are using it before the ajax response is loaded into the table.
    Kevin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0
    edited November 2020

    In the test case which u have provided, along with array we are getting some other attributes .

    Please see the logged ouptut.

    _Api(10)0: (6) ["Angelica Ramos", "System Architect", "London", "36", "2009/10/09", "$2,875"]1: (6) ["Ashton Cox", "Technical Author", "San Francisco", "66", "2009/01/12", "$4,800"]2: (6) ["Bradley Greer", "Software Engineer", "London", "41", "2012/10/13", "$3,120"]3: (6) ["Brenden Wagner", "Software Engineer", "San Francisco", "18", "2011/06/07", "$3,750"]4: (6) ["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$4,525"]5: (6) ["Bruno Nash", "Software Engineer", "London", "38", "2011/05/03", "$4,200"]6: (6) ["Caesar Vance", "Technical Author", "New York", "21", "2011/12/12", "$4,965"]7: (6) ["Cara Stevens", "Sales Assistant", "New York", "46", "2011/12/06", "$4,800"]8: (6) ["Cedric Kelly", "Javascript Developer", "Edinburgh", "22", "2012/03/29", "$3,600"]9: (6) ["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$5,300"]$: ƒ ()ajax: {dt_wrapper: true, json: ƒ, params: ƒ, reload: ƒ, url: ƒ}cell: ƒ ()cells: ƒ ()clear: ƒ ()column: ƒ ()columns: ƒ ()context: [{…}]data: ƒ ()destroy: ƒ ()draw: ƒ ()i18n: ƒ ()init: ƒ ()length: 10off: ƒ ()on: ƒ ()one: ƒ ()order: ƒ ()page: ƒ ()row: ƒ ()rows: ƒ ()search: ƒ ()selector: {rows: "", cols: null, opts: {…}}settings: ƒ ()state: ƒ ()table: ƒ ()tables: ƒ ()__proto: Object(0).

    and also i am getting data here, and what if i want to get the rows of the current page

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    As Kevin said, please update the test case to demonstrate the issue,

    Colin

  • JanurajJanuraj Posts: 85Questions: 18Answers: 0
    edited November 2020

    @colin http://live.datatables.net/yuqicuni/1/edit, in the same test case which kevin gave me i am pointing to

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

    In the test case which u have provided, along with array we are getting some other attributes .

    The docs for rows().data() state this for the returned value:

    DataTables API instance with data for each row from the selector in the result set. Each entry is the original data source object for that row, be it an array, object or Javascript object instance.

    If you just want a Javascript array you can use toArray(). Here is the updated example:
    http://live.datatables.net/yuqicuni/2/edit

    Kevin

This discussion has been closed.