Possible to initialialise table based on user's click on previous page?
Possible to initialialise table based on user's click on previous page?
austintnacious
Posts: 2Questions: 0Answers: 0
Hi,
I've just discovered DataTables. . . super cool!
I'd like to filter a table based on a users click on the previous page.
Is it possible to do set up my links with some name=value pairs
(e.g. "?filter_table_by_column=Boat Name&display_only=HMS QMII")
Or is there some other way to tell the page containing the DataTable enhanced table which rows to display based on the user's selection on the previous page?
I've just discovered DataTables. . . super cool!
I'd like to filter a table based on a users click on the previous page.
Is it possible to do set up my links with some name=value pairs
(e.g. "?filter_table_by_column=Boat Name&display_only=HMS QMII")
Or is there some other way to tell the page containing the DataTable enhanced table which rows to display based on the user's selection on the previous page?
This discussion has been closed.
Replies
You should be able to use the fnFilter api function. Take a look at this: http://datatables.net/api.
Grab the filter value you passed to the page and use it as the parameter for the api function.
If you want to apply it only to a specific column, you can specify the column index as the second parameter.
See here for an example: http://datatables.net/examples/api/multi_filter_select.html
But as I'm a Javascript Dunce it's taken me a while to get to where I am.
I want to go further with this but I'm stuck.
So I have links set up as
[code]href="document.htm?display_only=FILTER_STRING&filter_table_column=0"[/code]
in document.htm I have some js code which I found via searching the web and which allows me to use the query string name=value pairs from the URL. . .
[code]
function querystring(key)
// querystring
// Call function by x = querystring("variable") returns variable=x
{
... etc ...
}
querystring_Parse();
[/code]
I can then work with these in DataTables using the info that I got here. . .
[code]
var filt;
filt = querystring("display_only");
var col;
col = querystring("filter_table_column");
var oTable;
$(document).ready(function() {
oTable = $('#schedule').dataTable();
oTable.fnFilter(filt,col);
[/code]
this is GREAT!!!
I can now have a master table which I use as a source for info based on users' clicks.
But now I want to do some more with the DataTable enabled table.
I'd like to do some of the stuff I see described elsewhere on the site.
I'd like to turn on JQueryUI
[code]"bJQueryUI": true,[/code]
move parts of the table around
[code]"sDom": '<"top"i>rt<"bottom"flp<"clear">'[/code]
etc. but I can't find the correct way / syntax to do this.
I either get a warning that I can't re-initialise the table "make changes using the API" but I can't work out how to use / correct syntax for fnSettings.
I've taken the example from the site and I can get the page give me the iDisplayStart alert.
But I can't work out how to configure the DataTable having opened it using the API.
I don't even know what I'm asking here. . .
[code]$(document.ready(function() {
oTable = $('#schedule').dataTable({
"bJQueryUI": true,
"sDom": '<"top"i>rt<"bottom"flp<"clear">'
} );
} );[/code]
The API lets you modify/gather some data, but the big features are all usually enabled through the initial dataTable call.
See this page for a full list of things you can initialize with: http://datatables.net/usage/features
Here is an example that shows feature enablement: http://datatables.net/examples/basic_init/filter_only.html
Hope This Helps