tabindex and sorting

tabindex and sorting

pbercepberce Posts: 15Questions: 2Answers: 0
edited January 2013 in DataTables 1.9
I'm creating a table with form input elements in every table cell for editing data on a large scale. The requirement I have is the tabindex goes up and down, not left and right. I can easily set this up for the initial load of the page, the problem is it all goes out the window on a sort.

So my question is, is there a way to iterate through the visible elements to assign a new tabindex to each input element after each sort?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think you'll need to use fnDrawCallback to re-run whatever function it is that you are using to define the tabindex on your initial load. That will run your function on each draw, and have it always correct.

    Allan
  • pbercepberce Posts: 15Questions: 2Answers: 0
    edited February 2013
    Allan,

    I've been unable to figure this out and hoping you can help. A little background first. This is how I'm initializing my table

    [code]

    $('#product_grid_form').submit( function() {
    var sData = oTable.$('input').serialize();
    } );

    var oTable = $('#product_grid').dataTable();

    ...



    column header
    column header
    column header
    ...
    ...



    <?php
    $results = mysql_query("SELECT * FROM example")
    while ($row = mysql_fetch_array( $results );) {



    ...
    ...

    }

    ?>


    [/code]

    I didn't include any of the datatables initializations as I don't think they are important to my question.

    What I am looking to do is a custom tabindex order for all of the VISIBLE elements on the page. I'd like to have the tabindex go down in columns, so the first element would be tabindex="1", the element below it would have tabindex="2" and it would wrap around for each column so the element to the right of the first element of this would be tabindex="51" (row+displayed row number). Below is an example of what the tabindex would look like

    1 51 101 151
    2 52 102 152
    3 53 103 153
    4 54 104 154
    5 55 105 155
    ...
    ...

    You suggested using fnDrawCallback to handle this. My problem is the information passed into fnDrawCallback, oSettings, doesn't seem to contain the information I'm looking to change. Where do I go from here?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > I didn't include any of the datatables initializations as I don't think they are important to my question.

    Probably not, but fnDrawCallback is needed. What I'd suggest you do is take a look at this example: http://datatables.net/release-datatables/examples/api/counter_column.html . That will reindex the first column on a sort or filter, which is basically what you want, but rather than checking the value of the cell, you want to set the tabindex attribute.

    Allan
This discussion has been closed.