iDisplayLength & Server Side Processing - Quick Question

iDisplayLength & Server Side Processing - Quick Question

UPEngineerUPEngineer Posts: 93Questions: 0Answers: 1
edited August 2010 in General
Alan,

I am using the new "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]] method you introduced in 1.7.

However, since I am using server-side processing using PHP, my sLimit query fails account the "-1".

As a workaround, I added this to the $sLimit query:

[code]
/* Paging */
$sLimit = "";
if ( $_GET['iDisplayLength'] == '-1' ) {
$sLimit = "";
} else {
if ( isset( $_GET['iDisplayStart'] ) )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
} // End if statement is All (-1) is selected
[/code]

It appears to work just fine, but before I get too far into this, you don't see a problem doing this do you?

And by the way, I had a question on another post about being able to delete "all" the records using fnDeleteRow() on DOM side, not server-side. I get an error when trying to delete the last row instead of giving me "No records found". Is there a way or workaround for this?

You have a wonderful product that has made our lives easier and would like to give you a big thanks!

Scott

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Scott,

    Your server-side script modification looks absolutely fine. The only thing to be aware of (which I'm sure you are, just pointing this out for anyone else reading this), is if you have a table with a lot of rows - it would make complete retrieval of your database trivial for someone who is data mining - something you may or may not want to consider).

    There is a bug in 1.7.0 with -1 length and server-side processing unfortunately - however, there is a fix: http://datatables.net/forums/comments.php?DiscussionID=2440&page=1#Item_2


    fnDeleteRow - sorry I missed your other question. fnDeleteRow (and it's friends like fnAddData) aren't really expected for use with server-side processing - they will cause the table to be redrawn, and get the information again from the server - usually causing the row to be displayed again. So what needs to happen is an XHR to delete the row, and then a call to fnDraw to update the table - hopefully this will allow it to all work correctly.

    Allan
  • UPEngineerUPEngineer Posts: 93Questions: 0Answers: 1
    Allan,

    Thanks for replying. All of our tables are in a secure area and the user must be logged in to use the site. Hopefully, that will take care of the data miners :)

    On my second issue, when I was getting this error for deleting all the rows one by one, I was not using server-side.

    I had a table with a few colums and a radio button. When you click on the radio button, the click event calls the fnDeleteRow() and it works great. Until you try to delete the last row. You then get an error.

    I tried trapping the error with no success. I assumed that when the last row was deleted, the standard "No data in table" or whatever you wanted would display.

    So if I had a table with say 10 records created completely client side and tried to delete each of those 10 rows one by one it would error out on the last one. You can delete them in any order but can't delete them all :(

    Once they were all deleted, I would then update that batch in the database instead of updating row by row.

    Hope that is as clear as mud LOL

    Thanks again
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Scott,

    I've just tried the following:

    [code]
    $(document).ready(function() {
    $('#example').dataTable();
    $('#example').dataTable().fnDeleteRow(0);
    } );
    [/code]
    On a table with only a single data row in it. The row gets deleted, and the 'no data' message is displayed. Are you using DataTables 1.7 (which changed a few things with the deleting - although it should still work fine with 1.6.2 and before)? And passing '0' as the last index to be deleted (or are you passing the node in)?

    Allan
  • UPEngineerUPEngineer Posts: 93Questions: 0Answers: 1
    Allan,

    I have a table and a radio button as the last column. When the user clicks the radio button the below code fires. Basically, I may have 10-15 rows and when I click on the row, that row is "verified" (a term used with our app) and then disappears. The goal is to have all of them "verified".

    This is what I have:

    [code]
    // Delete the row clicked on
    $('#declined_claims tbody input').live('click', function () {
    oTable.fnDeleteRow(this,null,true);
    });
    [/code]

    Like I said, it works fine until the last remaining row is clicked, then I get an error. I know I am close, just can't get over the hump.

    And yep, using 1.7.0

    Thanks,
    Scott
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The value of 'this' which you are passing to fnDeleteRow is going to be the 'input' element there. I'm a bit bothered by the fact that it works at all! I'd suggest trying this.parentNode as the parameter to pass to fnDeleteRow... I might have a look at throwing an error / warning there...

    Allan
This discussion has been closed.