I am currently working on a laravel 5.4
project in which I have successfully implemented a datatable using DataTables jQuery Plugin
. This datatable(#sample_1
) includes a search field by default which works fine and filters records based on search.
The datatable is available at /home/loan
I want to know if there is any way I can load the above page with a filtered list of records by passing the search string to the search field of datatable. ex: /home/loan?search=bella
Upon inspecting my datatable html code in chrome I found datatable search has
<label>Search:
<input type="search" class="form-control input-sm input-small input-inline" placeholder="" aria-controls="sample_1">
</label>
I believe This is included by the datatable plugin. I could not find a way to assign name/id to it so that I can try doing /home/loan?search=bella
I think that would be the simplest way if it worked.
But here is the javascript
var initTable1 = function () {
var table = $('#sample_1');
// begin first table
table.dataTable({
// Internationalisation. For more info refer to http://datatables.net/manual/i18n
"language": {
"aria": {
"sortAscending": ": activate to sort column ascending",
"sortDescending": ": activate to sort column descending"
},
"emptyTable": "No data available in table",
"info": "Showing _END_ out of _TOTAL_ loans",
"infoEmpty": "No loans found",
"infoFiltered": "(filtered1 from _MAX_ total loans)",
"lengthMenu": "Show _MENU_",
"search": "Search:",
"zeroRecords": "No matching loans found",
"paginate": {
"previous":"Prev",
"next": "Next",
"last": "Last",
"first": "First"
}
},
"bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
"lengthMenu": [
[11, 20, 30, -1],
[11, 20, 30, "All"] // change per page values here
],
// set the initial value
"pageLength": 11,
"pagingType": "bootstrap_full_number",
"columnDefs": [
{ // set default column settings
'orderable': true,
'targets': [0]
},
{
"searchable": false,
"targets": [0]
},
{
"className": "dt-right",
//"targets": [2]
}
],
"order": [
[1, "asc"]
] // set first column as a default sort by asc
});
Please help me with this