Queuing changes in Editor not working when Serverside is true
Queuing changes in Editor not working when Serverside is true
Khalid Teli
Posts: 251Questions: 71Answers: 0
I ma using the example given in https://datatables.net/blog/2017-10-24#Multi-row-editing.
Everything works as expected when "serverSide": false
and doesn't work when "serverSide": true
My code looks like this:
var editorOpts = {
"table": "#mssr_list",
"fields": [ {
"label": "Product Code:",
"name": "product_code_fk"
} ,
{
"label": "Name:",
"name": "m_1"
}
]
} ;
var changedRows = [];
var localEditor = new $.fn.dataTable.Editor( editorOpts );
localEditor.on('postEdit', function (e, json, data) {
changedRows.push( '#'+data.DT_RowId );
tableone.buttons([3,4]).enable();
console.log(changedRows);
});
var ajaxEditor = new $.fn.dataTable.Editor( $.extend( true, {
ajax: '../../controllers/xxx_fetch.php'
}, editorOpts ) );
var tableone = $('#mssr_list').DataTable( {
"processing": true,
"serverSide": true,
"scrollY":"800px",
"scrollX":"100%",
"scrollCollapse": true,
"ordering": [],
"stateSave": false,
"info": true,
"dom": 'lBrtip',
"ajax":"../../controllers/xxx_fetch.php",
"columns": [
{ data: "product_code_fk" },
{ data: "m_1"}
],
select: true,
buttons: [
{ extend: "create", editor: ajaxEditor },
{ extend: "edit", editor: localEditor },
{ extend: "remove", editor: ajaxEditor },
{
text: 'Save changes',
init: function () {
this.disable();
},
action: function () {
ajaxEditor
.edit( changedRows, false )
.submit();
changedRows.length = 0;
tableone.buttons([3,4]).disable();
}
},
{
text: 'Discard changes',
init: function () {
this.disable();
},
action: function () {
this.ajax.reload();
changedRows.length = 0;
tableone.buttons([3,4]).disable();
}
}
]
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Please be more specific about the problem description.
Kevin
@kthorngren
sorry, if my question was not framed right.
What I am saying is that, when I use the code given in the example above it works fine when working on client side, that is when in the datatales initialisation I make
Server side: False
.
But as soon as I shift to server side processing by changing
serverside:true
the code doesn’t work.Saying it doesn't work doesn't give us any information to start helping.
Do you get alert messages or errors in the browser's console?
What are you using for your server side script?
Does the problem happen when you click the "Save" button?
Using the browser's network inspector tool what is sent to the server and what is the response?
Or please post a link to your page or a running test case showing the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren
1)
In the scenario 1 , where I use
serverside:false
. when is click theedit button
, window pops up up and then I enter the fields and on clicking theupdate button
inputted data gets displayed in table. And upon clicking thesave button
, the updated data gets send to the server which I confirmed usingdeveloper tool > network tab
. Finally, the updated data gets saved in database and displayed in table2)** in the scenario 2: ** when I use
serverside:true
. when I click theedit button
, window pops up up and then I enter the data in fields and on clicking theupdate button
The form data that gets sent is shown below and the response is the data which was there before edit which then gets displayed in table:Both times it doesn't show any error in console window.
My client side code looks like this:
................
{ data: "m_12"},
{ data: "no_of_stock"},
my server side code looks like:
......
.......
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
That request to the server looks like the request sent for the table draw after editing. Is there a request sent when you click the save button? What is in that request?
What is the output of this console.log?
Kevin
And when I click save button ,at same time** two requests** get sent
a) Form data with old inputs (data before edit)
b)
output of
console.log(changedRows);
is["#row_31"]
Server-side processing and the queuing changes example are mutually exclusive. They fundamentally cannot work together because of how each operates.
The queuing changes uses DataTables as a data store - the information in the table is held in the table, so that when ready to submit to the server the table data can be read and submitted.
With server-side processing, the data shown in the table is basically readonly. Any change to the data needs a re-read from the server. This is why you can't use things like
row().data()
as a setter with server-side processing - the next draw would just wipe it, since the server hasn't been told about the change.I'm sorry to say, I don't see a way how the two can be used together.
Allan
@allan Please update the blog entry to note that server side processing is not supported. I scanned through the doc for this before trying to help and did not see anything about server side processing.
Kevin
Yep, @kthorngren, that's a good suggestion. I'm updating it now, and it'll be pushed on the next site build,
Colin
Thank you . I will look for a different strategy