Editor will only delete if it has completed an Edit or Create first

Editor will only delete if it has completed an Edit or Create first

Jeffrey ZolaJeffrey Zola Posts: 4Questions: 2Answers: 0

I am using the latest versions of DataTables (1.10.25 - from CDN) and Editor (2.0.4 - local from recently purchased license download).

My use case calls for multiple pairs of editable tables within a tab of a very complex GUI that is created within the ASP.NET MVC5 framework. I have set up the .NET library with custom parsing of the form contents because the update and create need to touch several database tables.

The pair of tables represent different types of the same data for a claim payment. The data in each table has the same structure except for one column that has no value in one ("Header" data), but needs to be represented by a select list in the other ("Line" data).

The pair of tables needs to be repeated for each payment found for each claim. There are usually no more than two payments - but that is not an absolute.

I am not able to post any code because the use case involved proprietary elements.

I have copied and modified several examples (https://editor.datatables.net/examples/inline-editing/fullRowCreate.html & others).

The Edit functionality needs to be performed inline. I have essentially used the code of that example for the inline edit. My Create functionality uses the normal button and form and that is working (and sending proper default values for all of the hidden columns. The Remove functionality can be triggered in two ways - an inline icon like in the example, as well as with selection of rows and a button (using as-configured buttons).

I have created a common POST endpoint for all updates (both tables of each pair). I have dedicated GET endpoints that need to accept a parameter that represents the ID of the data's payment. It all seems to work properly when the GUI is transmitting the AJAX requests.

The problem is that a Remove operation CANNOT be the first one to be performed on each table, once initialized. Rows can be removed using both mechanisms I've created/cloned, but only AFTER any row has been edited or one has been created. There is simply no AJAX request being generated by the editor instances for removals until it has first completed a creation or edit. This behavior is repeated for each table. EVERY table needs to update or create before it can delete.

My intuition is that the API is confused by the multiple editor & table instance pairs that are needed. I have tried different ways to ensure that each line/header pair has a different, isolated scope from other pairs. I have been spinning my wheels on different aspects of this project for several weeks. I have found the online Manual, examples, and forum to be helpful - but cannot understand how the AJAX requests for deletion operations are not generated until create or edit operations have completed. When the deletion requests are sent, they work perfectly - but the interface will NOT send one until an update or create has completed. So weird....

Any suggestions are welcome!

Answers

  • Jeffrey ZolaJeffrey Zola Posts: 4Questions: 2Answers: 0

    I think I solved my problem......

    I need to ensure that the preSubmit callback is returning "true" whenever the action is "remove." For some reason, my validation was silently rejecting all deletions until the table was modified by a Create or Edit.

    I pulled out about half of the hair on my head trying to figure this out! :s

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Hi,

    Thanks for the update - good to hear that you've got this working now! Yes, preSubmit needs to be handled quite carefully at time

    I pulled out about half of the hair on my head trying to figure this out!

    I've tried superglue after a similar debugging session. I don't recommend it ;).

    Allan

  • Jeffrey ZolaJeffrey Zola Posts: 4Questions: 2Answers: 0

    Thanks for your response, Allan. I have been using DataTables for many years, and this is the first project for which I have needed edit capability. It took some time to understand some of the nuances of the API for both the native tables portion and now the Editor. Overall, I find DataTables to be a great plug-in. Very easy to enable, and it's default configuration provides great functionality. It's very flexible, and allows for customization to accommodate quirky use cases.

    I wrote up the original post at 11PM, after refactoring/rewriting my application 2-3 times to make sure I hadn't missed anything in the example that was causing this. A couple days ago, I had encountered a situation when I added the delete functionality that no deletion would occur. I searched the internet and forum and found that it could be caused by validation failures. I remembered that after hitting the "post" button on my question. So I went into my preSubmit callback and saw that the editor was inError for that first deletion, but ones after another action had completed.

    Why would a deletion as the first action of the API after instantiation not validate? Is there something in the "guts" of the Editor that doesn't get configured properly until it is used?

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Editor clears errors when a submission is completed. The reason for that is so to next edit / create / delete action has a clean slate. So if there is nothing that would put the form back into an error state, then it would pass the second time around.

    So the question becomes, why was it in the error state for the first one? I'm not sure! If you have a link to a page showing the issue I could take a look.

    Thanks,
    Allan

Sign In or Register to comment.