How can I change the initial query, based on a query string/parameter?
How can I change the initial query, based on a query string/parameter?
I am using js to retrieve the query string. I want to modify the initial request before the initial data is loaded. I tried doing everything on initComplete, which is a little too late, but I cannot even get the table to redraw at this point.
I have a dropdown menu with authors, and I am try to select the author based on the query string passed:
i tried this:
initComplete: function () {
var author = "My Author Name";
$('#authors-filter').val(author);
table.column(2).search(author).draw();
}
Technically this should change the dropdown menu to the correct author, and the second line should redraw the table. However, it seems like "draw()" is not doing anything.
Any ideas on what the issue is?
Answers
Here a couple of things I have also tried;
Setting the values I want in the column definition:
That doesn't work
Setting the values I want by modifying the ajax data:
This partially works. The filter works but it also overrides all other columns. So what I need is to modify an existing data value, instead of overwrite it.
PS: I finally figured out how to use the code blocks.
I don't know if this is the proper solution but I found that I can update the initial query by changing the ajax data using a function:
Hi,
If you want to define an initial column filter for the table, the
searchCols
can be used for that.However,
ajax.data
can also be used - although you'll always be setting column index 2 search toget_author
that way.Allan
I don't mind setting the column index in this case. You don't set the index with searchCols but you have to declare null for the other cols. So either way if the column changes the js code would need to change too.
Yes - as I was typing my message above I was thinking "I really must change this for the next major version"....
Allan