Bug with Index Column?

Bug with Index Column?

RockbRockb Posts: 97Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
A curious problem: The numbers (the index column) appears on the first page, but after clicking on a different like the 2nd or the 100th page, it will change to the "real" entry for this field. Independent If I choose a blank field for generating the index column or a "real" column.

In former times I used

[code]"fnDrawCallback": function ( oSettings ) {if ( oSettings.bSorted || oSettings.bFiltered ){for ( var i=0, iLen=oSettings.aiDisplay.length ; i

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Maybe this has to do with the server-side processing?

    You are using server-side processing in your local use I guess? Certainly I don't see the problem you indicate on the example you link to - unless I'm really confused (I'm thinking I'm just partly confused).

    In which case yes, its is due to server-side processing since the update of the indexes only operates on the client-side where the rows are. If the rows aren't present (which they aren't for other pages in SSP mode) then they can't be updated!

    Allan

  • RockbRockb Posts: 97Questions: 0Answers: 0

    No, it's on a public web server. I'll send you the link.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    edited May 2014

    Thanks for the link - however, as I say, the problem is that you are using server-side processing, it is not a bug in DataTables. You'd need a different solution than the one presented in my client-side code.

    I'd say you have three options:

    1. Modify the data at the server (the ideal solution)
    2. Modify the data as it comes back from the server
    3. Edit the draw callback function to take into account the page start position.

    Allan

  • RockbRockb Posts: 97Questions: 0Answers: 0
    edited May 2014

    Thank you, Allan, for your answer - and every other problem solving before. I really appreciate that and I know that many benefit from your script and from all of your help. If my content will get some money by micropayment, which I am planning to do, I will donate you - that's understood.

    To your suggestions: Modifying my data on the server won't help, or? For sure I can set an index column, but this doesn't make sense while ordering the columns. Or what exactly do you mean by that? Maybe you will find the time and could offer a tiny snippet to the server side examples http://www.datatables.net/examples/server_side/index.html - I think there are a lot who are using ssp AND who needs an index, or?

  • RockbRockb Posts: 97Questions: 0Answers: 0

    I've started a topic on stackoverflow, cause I'm unable to do this index column - and Allan has too much to do. Hopefully the community there will find a solution.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Modifying my data on the server won't help, or?

    Sure it will - just take the start position in the data, and count from there to the end. You don't need to read the information from the database, just calculate it in the script and then dump it back to the client. For example, if you know that the first row requested by DataTables is row index 10 (which you do from the parameters sent to the server), then you want to show the row index as 11 (i.e. add one, so the user sees it counting from 1). Then for each row outputted add one.

    I think there are a lot who are using ssp AND who needs an index, or?

    Possibly, but its the first time I've seen this question :-). I'm sure that if you post your solution others would greatly appreciate it.

    Allan

  • RockbRockb Posts: 97Questions: 0Answers: 0
    edited May 2014

    Okay, here we go :-)

    In examples/server_side/scripts/server_processing.php (download package) change this

    echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );
    

    ...to...

    $result=SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns );
    $start=$_REQUEST['start'];
    $start++;
    foreach($result['data'] as &$res){
        $res[0]=(string)$start;
        $start++;
    }
    echo json_encode($result);
    

    ...and for sure don't forget to add a pseudo-column to (e.g.) the first column in the same file above. For example:

    array( 'db' => 'Name', 'dt' => 0 ),
    array( 'db' => 'Name', 'dt' => 1 ),
    array( 'db' => 'Street', 'dt' => 2 ),
    

    AND in the table itself. That's it.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Good stuff :-)

    Allan

This discussion has been closed.