How do you get the cell contents based on a unique row id, (record primary key) and column index

How do you get the cell contents based on a unique row id, (record primary key) and column index

aCoradatatblaCoradatatbl Posts: 16Questions: 7Answers: 0

Hi,
Most examples show how to use the row number but not a unique primary-key which in my case is a hidden column (column one). Using row number is only useful if you're not using paging since row 5 page 1 is not the same content as row 5 page 12. Also my column titles were hard-coded into the tables <th> so datatables probably doesn't know about them programmatically so column index would probably be wiser.

cheers

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    See if any of the row-selector selectors will help for your situation. Maybe you can use the ID String selector along with assigning your row ID column to the rowId option.

    Kevin

  • aCoradatatblaCoradatatbl Posts: 16Questions: 7Answers: 0
    edited November 2018

    Thanks for the pointer @Kevin,
    After a couple of hours messing about i managed to do it with row id and cell(). for anyone else with the same issue heres the code i used :

        var idrow  = dTblOverview.row("#"+dashb_tbl_row_pk);
        var cellContent = dTblOverview.cell(idrow,2).data();
    

    dashb_tbl_row_pk - being the id on each row i stored in a page-level variable. The second arg of the cell() method is the index of the column you want, in my case i have the first two columns hidden( column 0 and column 1).

    Oh, and dTblOverview - is the variable holding my element instance of datatable().

    NOTE: Only works with id's hence '#', not classes '.'

    Hope this helps anyone who needs it too!

    Cheers

This discussion has been closed.