Reputation: 9518
I have a website where I'm using datatables and I want to automagically submit a search from a GET variable. I have no trouble getting the GET variable into the search input, I just can't seem to submit it. It's not a form, so submit()
is worthless. I'm trying to have jQuery trigger an ENTER, but it's not working. Here's the javascript at the bottom of my php file where the datatable is:
$(document).ready(function() {
var table = $('#responses-table').DataTable({
dom: 'B<"clear">lfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf','print'
]
});
$('input').val("<?php echo $_GET['id'];?>");
$('input').focus();
// this actually does nothing
var e = jQuery.Event("keypress");
e.which = 13;
e.keyCode = 13;
$("input").trigger(e);
});
Any idea what I'm doing wrong here?
Upvotes: 1
Views: 75
Reputation: 85578
I guess this is a case of "can't see the forest for the trees" :)
table.search("<?php echo $_GET['id'];?>").draw();
or
$(".dataTables_filter input").val("<?php echo $_GET['id'];?>").keyup();
both will fill the input box with the $_GET
value and perform the search.
Upvotes: 1