I would like to update the value of a field in database in client side. I did it in sever side, but I want the page to refresh after that. So, I thought this can be done when update in client side.
I would like to update the value of a field in database in client side
You can update a table field by using cell().data() or row().data(). This won't update a database on the server.
I did it in sever side, but I want the page to refresh after that.
If you are using the ajax option to load the Datatable then you can use ajax.reload() to reload the Datatable from the server. If you are using a jQuery ajax request to update the server side database you could use one of the API's above to update the client side instead of reloading the full table using ajax.reload().
If this doesn't help please provide more specifics about your solution so we understand exactly what you are doing to update the server database and how you want to update the client table.
I have a field called 'Status' when user apply its document the Status become Pending. The Admin can either Confirm or Reject it. When Confirm The background of the Status field become Green and Red when Reject. In case of Reject, the user can edit the uploaded document so the Status become Pending again, but the background still Red and need to refresh the page to change it. I want to change background when become Pending without refreshing the page.
I applied some css in client side and not update without refreshing the page.
How are you applying the CSS in the client? Are you using createdRow or columns.createdCell? If so you problem will need to use rowCallback instead which runs each time the row is displayed.
I run the code in localhost so you are unable to access it. Below I explained my problem in details.
I have a field called 'Status' when user apply its document the Status become Pending. The Admin can either Confirm or Reject it. When Confirm The background of the Status field become Green and Red when Reject. In case of Reject, the user can edit the uploaded document so the Status become Pending again, but the background still Red and need to refresh the page to change it. I want to change background when become Pending without refreshing the page.
Replies
You can update a table field by using
cell().data()
orrow().data()
. This won't update a database on the server.If you are using the
ajax
option to load the Datatable then you can useajax.reload()
to reload the Datatable from the server. If you are using a jQuery ajax request to update the server side database you could use one of the API's above to update the client side instead of reloading the full table usingajax.reload()
.If this doesn't help please provide more specifics about your solution so we understand exactly what you are doing to update the server database and how you want to update the client table.
Kevin
Thanks Kevin,
I updated the field in server side via preEdit, but the problem is I applied some css in client side and not update without refreshing the page.
Regards
@Sarbast Is this still an issue? I'm not clear if your last comment found a solution?
Colin
Hi Colin,
Yes still and not found solution yet.
Regards
Are you able to link to your page so we can see it please. I'm not clear if the issue is that the data is being updated, but the CSS isn't.
Colin
I have a field called 'Status' when user apply its document the Status become Pending. The Admin can either Confirm or Reject it. When Confirm The background of the Status field become Green and Red when Reject. In case of Reject, the user can edit the uploaded document so the Status become Pending again, but the background still Red and need to refresh the page to change it. I want to change background when become Pending without refreshing the page.
Regards
No still in localhost. Yes the problem in CSS
How are you applying the CSS in the client? Are you using
createdRow
orcolumns.createdCell
? If so you problem will need to userowCallback
instead which runs each time the row is displayed.Kevin
Hello Kevin,
I try rowCallback, but the problem not solve.
Then we will need to see the problem. Please provide a link to your page, you can PM Allan or Colin if you want to keep it private, or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Maybe post you relevant Datatables and Editor code here to see if something obvious stands out.
Kevin
I run the code in localhost so you are unable to access it. Below I explained my problem in details.
I have a field called 'Status' when user apply its document the Status become Pending. The Admin can either Confirm or Reject it. When Confirm The background of the Status field become Green and Red when Reject. In case of Reject, the user can edit the uploaded document so the Status become Pending again, but the background still Red and need to refresh the page to change it. I want to change background when become Pending without refreshing the page.
Regards
Please post your relevant Datatables and Editor code so we can see what you have.
Kevin
Hello Kevin,
The problem solved after I add CSS to "Pending" status in rawCallback.
Thanks alot Kevin and Colin