.remove() deletes all table data not just one record

.remove() deletes all table data not just one record

mpcleverdonmpcleverdon Posts: 19Questions: 2Answers: 0
edited January 2015 in Free community support

Hi

I have been batling for a few days on this problem.

I have upgraded to DataTables 1.10.4 and editor 1.3.4 and tableTools 2.2.3 libraries and the css files too.

My main reason to move an old application to the new was to use the ssp.class.php functions for my table that are now growing larger.

I have the ssp.class working fine and also I can edit a single record without problems, bt when I use remove() it deletes all records in the table.

// Delete a record (asking user for confirmation)
    $('#owner_rentals').on('click', 'a.editor_remove', function (e) {
        e.preventDefault();
        editor
            .title('Delete row')
            .message( 'Are you sure you wish to remove this record?' )
            .buttons( 'Confirm' )
            .remove( $(this).closest('tr')[0] );
    } );

Both the edit and remove functions use the same selector $(this).closest('tr')[0]

Also the POST shows the id[] correctly with the single record id number

I cant find any subject on the forum that shows this problem so I gues I am doing something wrong ;-)

Replies

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Hi,

    Also the POST shows the id[] correctly with the single record id number

    In that case it sounds like an error in the server-side script rather than the Javascript code shown above. Are you using the Editor PHP libraries (if so, you don't need ssp.class.php as the Editor libraries have server-side processing support built in), or something else?

    Allan

  • mpcleverdonmpcleverdon Posts: 19Questions: 2Answers: 0
    edited January 2015

    Thanks for the prompt reply

    I use ssp.class.php for the DataTables side only, for the editor I use a standard php script that I have been using for DT 1.9 etc.. detailing the data colmuns which I believe I still need as I use british style dates etc...

    for the server side script I have used the "simple" one from the link to Github but also found the one that includes the "complex" option which gives me the filtering I need and works fine for the table.

    <?php
    
    // DataTables PHP library
    include_once( "lib/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    /*
    
    */
    Editor::inst( $db, "owner_rentals" )
        ->fields(
                Field::inst( "id" ),
                Field::inst( "ADate" )
                ->validator( 'Validate::dateFormat', 'd-m-Y' )
                ->getFormatter( 'Format::date_sql_to_format', 'd-m-Y' )
                ->setFormatter( 'Format::date_format_to_sql', 'd-m-Y' )
                ->validator( 'Validate::required' ),
                Field::inst( "Owcode" ),
                Field::inst( "Property" ),
                Field::inst( "PropertyID" ),
                Field::inst( "Concept" ),
                Field::inst( "Description" ),
                Field::inst( "Amount" ),
                Field::inst( "Currency" ),
                Field::inst( "RentalAmount" ),
                Field::inst( "DiscountAmount" ),
                Field::inst( "EntryDate" )
                ->validator( 'Validate::dateFormat', 'd-m-Y' )
                ->getFormatter( 'Format::date_sql_to_format', 'd-m-Y' )
                ->setFormatter( 'Format::date_format_to_sql', 'd-m-Y' ),
                Field::inst( "Nuser" ),
                Field::inst( "Accdate" )
                ->getFormatter( 'Format::date_sql_to_format', 'd-m-Y' )
                ->setFormatter( 'Format::date_format_to_sql', 'd-m-Y' ),
                Field::inst( "AccountNumber" ),
                Field::inst( "Attached_file" ),
                Field::inst( "Reference" ),
                Field::inst( "CurrRate" ),
                Field::inst( "RentalNotes" )
        )
        ->process( $_POST )
        ->json();
    
  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    The PHP above is what you use for the editing aspect of the table? It will handle server-side processing itself (example).

    Regarding it deleting all rows - I can't see any reason why it would do that!

    I would suggest removing Field::inst( "id" ) as id is automatically included as the primary key field (controlled by the optional third parameter of the constructor), but aside from that it looks okay.

    Can you link me to the page in question so I can take a look?

    Thanks,
    Allan

  • mpcleverdonmpcleverdon Posts: 19Questions: 2Answers: 0

    I will try to place a copy on a public site for you to take a look at.

  • mpcleverdonmpcleverdon Posts: 19Questions: 2Answers: 0

    OK

    here is a test table

    http://test.lanzarote1.com/progress.php

    I have now tried upgrading various tables to 1.10.4 which give me the same results except one which worked after adding idSrc:"id" to the editor. But in this example it makes no difference.

    Regards Mark

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Hi,

    I don't really want to try and delete a row incase I ruin your database! What happens if I do try to? Will it destroy your database?

    Allan

  • mpcleverdonmpcleverdon Posts: 19Questions: 2Answers: 0
    edited January 2015

    Yes it will, but as you can imagine it is just test data.

    Please test it but notice the response to the POST , it is empty although the table in the browser still holds the records until you resfresh the page.

    Editing instance is setup as follows:

    // DataTables PHP library
    include_once( "lib/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    
    Editor::inst( $db, "owner_acc_progress" )
        ->field(
                Field::inst( "InProgress" ),
                Field::inst( "AccountDate" ),
                Field::inst( "property" ),
                Field::inst( "owcode" ),
                Field::inst( "AccountNumber" ),
                Field::inst( "AccAmt" ),
                Field::inst( "AccCurr" ),
                Field::inst( "AccCfwd" ),
                Field::inst( "InvoiceNumber" ),
                Field::inst( "Paid" ),
                Field::inst( "Balance" ),
                Field::inst( "Notes" ),
                Field::inst( "DateStarted" ),
                Field::inst( "anul" ),
                Field::inst( "PayCurr" )
                )
        ->process( $_POST )
        ->json();
    

    Mark

    P,S. I have put a data replenish button on the page so you can retry as many time as you like.

  • mpcleverdonmpcleverdon Posts: 19Questions: 2Answers: 0

    Sorry Allan

    It was my fault , I had not placed the new php libraries in the right place and the page was using old version, this obviously caused the problem.

    Regards Mark

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Phew - good to hear :-). Thanks for the feedback (apologies I missed your reply before).

    Allan

This discussion has been closed.