Nomenator
Nomenator

Reputation: 1127

How to .draw() or add row on datatable without ajax reload?

Using row.add(…) on datatable, I find it using ajax call to refresh when I cause draw(), so I never see the new row, since it reloads the data from database.

The underlying UX logic is as follows: Table contains data editable through inputs. Inputs validate in change and if all the inputs inside the row contain valid data, submit new data to the back end, then reload from the database after server reports success. User wants to add a new row. Valid data cannot be generated and null values are not allowed, so a new empty row is created and as soon as all the inputs have valid data, it is submitted to the back end in the same manner.

Question: how to add row to datatable without triggering ajax.reload()?

Upvotes: 3

Views: 1433

Answers (1)

Nomenator
Nomenator

Reputation: 1127

I figured out an alternative solution:

When passing data from server to the ajax call, I append one empty object at the end results.Add(new AjaxTableObject()); and this causes the table to always display an extra line of empty data. The user-facing javascript logic remains the same: as soon as the row’s inputs are valid, it submits data to the server.

I’m not going to mark this as the right answer because it does not answer the original question posted, but I’ll leave it here because it might be useful for other people who are trying to do this same thing.

If anyone knows the answer to the original question, please post it, it will be useful for other applications.

Upvotes: 2

Related Questions