Editor delete...but not really ;)

Editor delete...but not really ;)

psenechalpsenechal Posts: 32Questions: 2Answers: 0
edited October 2013 in Editor
Ran into a unique situation today and would like to know if I can save myself a crap load of coding. I have a regular datatable with editor (we have hundreds). On this particular table, deleting a record isn't actually deleting the record...the server side code just enters a delete date in one of the columns. Records with a delete date still show up in the table list, only I have them colored red.

Here's my dilemma. I'm using the normal editor.remove function to do this, and when clicking submit, the row is removed client side from the dom. If I refresh the page, the row appears back in the dom as it should. Is there a way to run the editor.remove function, but prevent it from removing the row from the dom.

My guess is that you're going to say "use the ajax reload", which I've thought about...however, I'd prefer not to download another 1200 records from the database if I don't have to. If I have to...well, ok. But I thought I'd at least ask if there was a way to interrupt the editor.remove function so the dom isn't affected.

You're the best! Thanks!

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Rather than using the `remove()` method, I've suggest simply using `edit()` where the edit is automated and will set the value of the date field:

    [code]
    editor.edit( tr, null, null, false );
    editor.set( 'date', '---' ); // set to whatever value
    editor.submit( function () {
    table.fnDeleteRow( tr );
    } );
    [/code]

    Where:

    * `tr` is the TR element of the row to be edited
    * `editor` is the Editor instance
    * `table` is the DataTable instance

    So what is happening is that the edit command runs, but as soon as it is complete, it is deleted on the client-side. So to work with that, on initial load you'd also have your script filter out all rows that have been "deleted".

    Its very useful for retaining old records that you don't want the user to see, but you do want on the server, as you know!

    Regards,
    Allan
  • beckypbeckyp Posts: 1Questions: 0Answers: 0
    edited December 2013
    [quote]allan said: Rather than using the remove() method, I've suggest simply using edit() where the edit is automated and will set the value of the date field[/quote]

    Hi! I'm trying to do something similar. I seem to be having a problem with the editor.submit. I took out the predefined delete button and created a button that extends select_single. I set the fourth parameter of editor.edit to true so that I could see that the editor had pulled the correct row and location_is_active is set to 0. All of that works just fine, but when I add the line for editor.submit, it gives an error on the form. Any suggestions?

    "oTableTools": {
    "sPaginationType": "bootstrap",
    "sRowSelect": "single",
    "aButtons": [
    {"sExtends": "editor_create", "editor": editor},
    {"sExtends": "editor_edit", "editor": editor},
    {
    "sExtends": "select_single",
    "sButtonText": "Delete",
    "fnClick": function() {
    var oTT = TableTools.fnGetInstance('location_view');
    var aData = oTT.fnGetSelected();
    editor.edit(aData, null, null, true);
    editor.set("location_is_active", "0"); // set location_is_active to 0
    editor.submit();
    }
    },
This discussion has been closed.