Retrieving hidden data element for each visible row

Retrieving hidden data element for each visible row

LesFLesF Posts: 16Questions: 6Answers: 1

I have an internal id in the row data, assigned to a hidden column, and I need to collect a list of these ids, for the current page.
I can't get it via jQuery because the hidden column is not rendered in HTML, so I need to get the data array for each row.
I can't work it out from the API docs, has anybody done something similar?

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    https://datatables.net/reference/api/column() and provide the class you gave the associated th.

  • LesFLesF Posts: 16Questions: 6Answers: 1

    I have a partial solution but need to refine this to retrieve just the data related to the current displayed page. This gets me all elements from the data array that the table is populated from, where rowData[0] is a hidden value not present on the table:

    var idList = [];
    var tbl = $("#summaryDataTable").DataTable();
    /*  All rows, not just current page: */
    tbl.rows(function(idx,rowData,node){
       idList.push(rowData[0]);
    });
    

    I am trying to work out how to get the same information for just the current page, and this seems to be the right approach but I cannot work out what object type the data() property is giving me here:

    var rows = tbl.rows( { page: 'current' } ).nodes();
    for(var rw in rows)
       alert(rw.data());
    

    Basically I want a reference to the underlying data array for each row displayed, in the current sort-order.

  • LesFLesF Posts: 16Questions: 6Answers: 1
    edited June 2016

    Ok found it. Still getting my head around the power of this tool :smile: The DataTables.Api is right there...

    var pageData = tbl.rows( { page: 'current' } ).data();
    for(var idx=0; idx < pageData.length; idx++)
       idList.push(pageData[idx][0]);
    

    I believe this is the most concise way to get what I need.

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    Can you please use DataTables Live so we can see a working example of the functionality you are trying to achieve.

  • LesFLesF Posts: 16Questions: 6Answers: 1

    No need as I solved my problem. My last post shows the solution, but I can't mark my own reply as the correct answer.

This discussion has been closed.