Best way to load a table with string parm
Best way to load a table with string parm
I am looking for some sample code for someone to enter a string into a text box, hit submit, and then load a datatable. I have built datatables but the issues I am having is for the text to make it to the server side code so that I can search on this code. Also, if someone clicks the button over and over, I am having issues with table loading correctly. Any sample code that could show the best implementation of this? Do I load the table in a var and rebuild every time?
This discussion has been closed.
Replies
In all seriousness, what have you tried so far? Can you show us the code / link to the page? Are you destroying the table on each click, or just reloading the ajax data?
Allan
The following is in my index file
[code]
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"sAjaxSource": "/source/process.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": 'txtId=' + $("txtId").val(),
"success": fnCallback
} );
}
} );
$("#btnSubmit").click(function(){
oTable.fnReloadAjax();
});
} );
Enter an id:
id
Surname
Name
[/code]
This is the process file:
[code]
<?php
$result="";
if (empty($_REQUEST["txtId"])) {
$result = '{"aaData":[["1","Surname1","Name1"]]}';
}
else {
$result = '{"aaData":[["2","Surname2","Name2"]]}';
}
print $result;
?>
[/process]
If I type something in the box it does nothing and when I run it, it just shows result 2. My goal is to have a page with an edit box and search button. When I type something in, it will launch the grid, pass the value to process, and process will act on that value. My goal is to just get a basic sample running.
Thanks for the comment...
> $("txtId").val(),
You want:
[code]
$("#txtId").val(),
[/code]
!
Allan