Remove --> Edit boolean

Remove --> Edit boolean

nico077nico077 Posts: 55Questions: 14Answers: 2

When i remove an element, i want to modify a boolean (0 --> 1).

But I don't want to remove the row of my database and i don't want to use event like PostEdit or PostRemove...

Why can i modify the data without events ?

Best regards,
Nicolas

This question has accepted answers - jump to:

Answers

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    Do you have an answer please ?

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin
    Answer ✓

    You are basically editing the data in this case, so I would suggest that you send an edit request to the server with the boolean value set as required. If you have a where condition set on the sever-side side script it will then just filter those values out.

    The easiest way is probably to have a second editor instance on the client-side that provides the ability to set that field field.

    I think this is a good topic for a blog post - I'll write it up soon.

    Regards,
    Allan

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    Thank you Allan,
    I find a solution but i can improve my script =)

    The solution :smile:

    $('#example').on('click', 'a.editor_remove', function (e) {
    editor
    .edit(null,false)
    .set( 'budget.suppression', 1 )
    .submit();
    } );

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    I have a probleme.

    When i use the script (published june 22),

    I've the message
    uncaught exception: Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11

    I use a hidden field with budget.suppression but it does'nt work...

    Best regards,
    NIcolas

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    I'd need a link to a test case showing the issue to be able to offer any help.

    Allan

  • nico077nico077 Posts: 55Questions: 14Answers: 2
    edited July 2016

    If you can't help me with this screenshot, i share my script.

    My example works with localhost but when i send on my server (screenshot)... It does'nt work !

    I search an other solution with this exemple : https://editor.datatables.net/examples/bubble-editing/inTableControls.html#

    I want to use the delete example to edit one field of my database.

    $('#example').on( 'click', 'a.remove', function (e) {
    editor
    .title( 'Edit one field of my database' )
    .buttons( { "label": "edit", "fn": function () { editor.submit() } } )
    .edit( $(this).closest('tr') ).set( 'budget.suppression', 1 ); ???
    } );

    Moreover I need to reload the page...
    Can i do like the remove function ? --> Remove the datatable' row but not delete in the datatable.

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    I'd really need a link to the page showing the issue, as I requested above I'm afraid. I need to be able to debug the live script and view the data that is being set to and from the server.

    Allan

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    Thank you for your quick response.
    It's very strange because when i test it on IE9, it's work but the script redirect on the index.php ?!

    I prepare the script and the database and i send it. What is your adress ? I don't want to post it on the forum.

    Thank you Allan,
    Best regards,
    Nicolas

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    I think it's more easy to explain my problem like this :smile:
    With the example
    https://editor.datatables.net/examples/simple/inTableControls.html

    I use

    // Edit record
    $('#example').on('click', 'a.editor_edit', function (e) {
    editor
    .edit(null,false)
    .set( 'office', 'test' )
    .submit();
    } );

    I want to update office (and insert the value test) in the clicked row...

    But it doesn't work...

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin
    Answer ✓

    You need to pass in the row into the edit() method. Otherwise it doesn't know what row to edit!

    Allan

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    Ok,

    My script works :smile:

    e.preventDefault();
    editor
    .edit($(this).closest('tr'),false)
    .set( 'budget.suppression', 1 )
    .submit();

    So can i refresh the datatable like the bubble or the remove function because when i edit the field 'budget.suppression', i want to take of the row of my datatable but not remove in the database.

    Thank you for your time.
    Best regards
    Nicolas

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    Hello Allan,
    I'm sorry but I still have my problem.

    I use this script and it's work but in my server script, i have a condition
    ->where( 'budget.suppression', '0', '=' )

    When i use the edit
    $('#budget').on('click', 'a.editor_remove', function (e) {

    The problem : the page reload. I lost my POST variables and the datatable reload...

    I want to use the remove function but only edit the 'suppression' field and take of the row of my datatable... not delete the row of my database !

    Have you got a solution ?

    Best regards,
    Nicolas

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    I'd need a link to the page showing the issue please. My guess is you might need to add:

    e.preventDefault();
    

    but without being able to see the full page, I'm just guessing.

    Allan

  • nico077nico077 Posts: 55Questions: 14Answers: 2

    Ok but when i use the e.preventDefault(); i've got this message

    SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

    'budget.suppression' is an hidden field.

    I send you an example.

    Thank you very much,

    Nicolas

  • allanallan Posts: 61,449Questions: 1Answers: 10,055 Site admin

    Sounds like an error in the server-side code. I don't know what server-side code you are using, and I don't know what the full client-side code you are using is. I would need that information to be able to offer any help.

    Allan

This discussion has been closed.