Datatables 1.10 - Pass a DOM field value to server side processing page
Datatables 1.10 - Pass a DOM field value to server side processing page
I have a DataTable setup like this that's processed in a ColdFusion CFC:
var user_table = $(this).find("table.permissions_user_table").DataTable({
"info":false,
"lengthChange":false,
"processing":false,
"serverSide":true,
"ajax":{
"url": "/cfc/intranet.cfc",
"data":{
"method":"processDatatables",
"element_type":"entity",
"element_id":"14",
"selected_users":getUserList()
},
"type":"post"
},
"columns": [
{ "data": "id" },
{ "data": "name" },
{ "data": "location" }
],
"order": [[0, 'asc'], [1, 'asc']]
});
The "getUserList()" is simply this:
function getUserList(){
alert("fire!");
return $("#user_list_field").val();
}
On initialization, the getUserList function runs, "fire!" pops up, and the DataTable is correctly created. However, when the table is redrawn, even if the user_list_field has a different value, the DataTable is redrawn with the original value of "selected_users." It doesn't fire getUserList(), but it still goes out to the server side code and processes the search or reorder correctly.
Is there a special way to reload the ajax.data from the DOM before processing the redraw?
Answers
Would it be possible to create and assign a function call to the data parameter instead?
This should in theory defer the execution of that function and provide the functionality you request, but limitations may apply as there is no way right now to validate your current form and its values. The assumption here is that
$("yourFormWithValues")
contains all the elements you wish to pass, so if you are just concerned with theselected_users
then you can adjust the return statement accordingly.Hope this helps,
I ended up finding a solution on StackOverflow. I had to set the
selected_users
list to a global variable and use a function to refresh/pass it. So, I got rid ofgetUserList()
, defined a global variablevar global_user_list = "";
above my$(document).ready()
function, and replaced line 12 above with this: