Im stumped - I just can't get this default filter to work..... :-)
Im stumped - I just can't get this default filter to work..... :-)
Gaz96
Posts: 20Questions: 6Answers: 1
$(document).ready( function () {
$('#naps').DataTable({
"columnDefs": [
{ "type": "date-uk", targets: 0 }]
});
} );
</script>
<script>
$(document).ready(function() {
var oTable = $('#naps').dataTable();
var myFilter = $_SESSION['username']
oTable.fnFilter( myFilter, 1 );
} );
</script>
This discussion has been closed.
Answers
Looks like it should work to me (assuming you output the PHP variable correctly to Javascript - the above code wouldn't work since it would be invalid Javascript - I'm not sure if that is a typo?). Can you link to a test case please.
Allan
Hi
There is a typo - there should be a ; at the end of line 12 but even after adding it it doesn't work. I tried putting apostrophes around $_SESSION['username'] but no joy.
[sigh]
Just had a thought - using .fnfilter doesn't require any extra prior referencing does it??
Your session variable isn't going to be interpreted by PHP at all. If you look at the console in your browser, do you not see a syntax error? We'd really need a link to a test case showing the issue, per the forum rules, to be sure, but I would imagine you'll need to do something like:
Allan
Morning. I just tried the syntax you suggested but no luck. The problem is it's not throwing an error - the page loads just fine and so does the table, but displaying all records without the filter applied. Exactly what can of a link do you need.....?
A link to the page so I can take a look and see what is going wrong.
It's in a kind of sandpit. You'll need to go here:
http://www.spyringcentral.co.uk/garywhite_glw/login.php
Login with the username {removed}, password {removed}
Then go to the competitions page where the naps table loads and the filter is supposed to restrict it to showing only records for him......
I know whats wrong - can I send you a screenshot....?? The variable myFilter is not populating......... The code is correctly reading the session variable but nothing..........
In this rendered code:
there are two issues:
oTable.search( myFilter );
the legacy fnFilter method is not available if you use the
$().DataTable()
form.Allan