Performing auto search
Performing auto search
jayshetti
Posts: 6Questions: 1Answers: 0
Hello how can i initialize value to search box and sort based on value initialized without human interaction. It should be done programatically is there any way to archive this?
Thanks,
This discussion has been closed.
Answers
Use
search.search
option to set an initial filtering condition on the table. After initialization this could be done withsearch()
method followed bydraw()
method.Use
order
option to set initial order during initialization. After initialization this could be done withorder()
method followed bydraw()
method.See more articles about jQuery DataTables on gyrocode.com.
Hi @gyrocode I am able to initialise value to search box but unable perform auto search
` $(document).ready(function() {
var table= $("#dataTables-example").DataTable({
responsive: true,
"bPaginate": true,
"bLengthChange": false,
"pageLength": 2,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false,
"ordering": false,
"rowsGroup": [2],
"oSearch": {"sSearch": " hg"},
"language": {
"search": "Find: ",
},
});
`
could you guide me how can use search() and draw() with this.
See this example for demonstration of using
search.search
option.See more articles about jQuery DataTables on gyrocode.com.
@gyrocode i used your example and included it in my code something like this.
var tables= $('#example').DataTable({
responsive: true,
"bPaginate": true,
"bLengthChange": false,
"pageLength": 2,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false,
"ordering": false,
"rowsGroup": [2],
search: {
search: '34'
}
});
but it is not performing search for me it only initialises value. But when i copied above snippet into your shared example it is working fine.
what could be the reason.
Possibly you are using an old version of DataTables? Hard to say without a test case - can you link to one please.
Allan
Hi @allan where can i get newer version of DataTables?
The download page .
I don't know if you are using an old version - as I say, without a test case I don't know.
Allan
Hello @allan
there is no problem with version.
Let me tell you what exactly i am trying to do.
I am fetching data from SQL in php and populating all fetched data into Table with customised UI.
To display it in table i am using Datatables.
var tables= $('#example').DataTable({
responsive: true,
"bPaginate": true,
"bLengthChange": false,
"pageLength": 2,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false,
"ordering": false,
"rowsGroup": [2],
search: {
search: '34'
}
});
when i do this it only initialises value 34 into search box but it does not perform search at all.
My ultimate aim is to display pagination at bottom when page get loaded with all data by performing auto search.
When i hit enter or space button into search box it performs search operation.
We'd need a link to a test case showing the issue. @gyrocode showed the
search.search
option working as expected.Allan
@allan i sent you link to your inbox.
Thanks for the link. There is a Javascript error happening on the page which is stopping the search from happening. That appears to be caused by an empty row (
<tr></tr>
) in thethead
element.Allan