Replacing legacy code when selecting a table row.

Replacing legacy code when selecting a table row.

RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
edited May 2014 in DataTables 1.10

So I had code that checked for the click event on a tbody tr so that I could tell when you clicked on a table row. The idea is that when a person clicks on the table row, I should figure out which column has the id (we allow reordering) and then get the data associated with that column to make a request for that record (a specific person in a list of people).

In dataTables 1.94 I was using

var data = oTable.fnGetData(This);
var col = oTable._fnColumnOrdering(This).split(",");

and then I was looping over the col until I found the column that had an 'id' string in it, and got the data associated with it. However with 1.10 the _fnColumnOrdering method no longer exists. So my question is how to get an array of the column names (which is what that method used to return).

This question has an accepted answers - jump to answer

Answers

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    edited May 2014

    I've got something half way working with getting the oSettings and looping over the aoColumns.sTitle to figure out the names. However when I randomize the columns the data associated is coming back in odd orders. For example I'd have the columns in the order of Birthday, First Name, Last Name and ID, but the data would come back as Last Name, Birthday, Id, First name. Not sure how to fix the fnGetData call so it returns them in the proper order.

    Here is a link to the table debugger. ujifej

    I'm also using the legacy ReorderWithResize plugin, as the resizing is something we really want to be able to keep.

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14

    So... Looking that the debugger output I can see why it's messing up... The data isn't being re-arranged properly which is almost certainly the Resize plugin messing up... Hmm... I guess I'll take a look there and see what I can find. Is there any intention to add re-sizing to ColReorder? Or atleast to patch ReorderWithResize to work with 1.10?

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Ah - the problem of using private functions :-) (in fairness, I probably shouldn't have exposed them...!).

    You could do this to find out the column index that was clicked on:

    $('#example').on( 'click', 'td', function () {
      var columnIdx = table.cell( this ).index().column;
    
      // do something with the column index
    } );
    

    Is there any intention to add re-sizing to ColReorder? Or atleast to patch ReorderWithResize to work with 1.10?

    Not on my part (on both accounts). I'm not really a fan of how that plug-in implements the resizing. I will, on day, do a resizing plug-in for DataTables, but there are a stack of other things currently taking priority.

    Allan

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14

    I got it to work so thanks! That makes sense, it's certainly not something that is all that important, I do hope that you're able to find time to write your own sooner than later though. =)

  • rvgrahamrvgraham Posts: 28Questions: 5Answers: 0

    I find it hard to think of a feature that I get asked about more than column resizing. it seems to be a core feature of all other grids I've used.

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Thanks for the vote! It is something I'll get around to doing one day (unless someone wants to sponsor it sooner? :-) ), but there are other things that I think are more important, such as responsive tables first.

    Allan

This discussion has been closed.