the search selection option in yajra datatables doesn't show all pages
the search selection option in yajra datatables doesn't show all pages
elmasry_n
Posts: 10Questions: 1Answers: 0
hello Dears,
I hope some help as i using yajra datatables with laravel
and the search selection option just show the current page as i using
'lengthMenu' => [[10, 25, 50, 100, 250, -1], [10, 25, 50, 100, 250, trans('lang.All')]],
i need to show all pages
and the below is my initComplete function code
this.api().columns([4,5]).every( function () {
var column = this;
var select = $('<select><option value=\"\"></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value=\"'+d+'\">'+d+'</option>' )
} );
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Are you using server side processing? If so then the server script is responsible for searching. In this case you will need to get support from the developer of the server side script (yajra datatables).
Kevin
Thanks kthorngren for your respond
No Iam not just I`m using UsersDataTable.php file and that's supported from yajra and the below my builder html code
by the way i made filterColumn as the below
are you recommend to ask yajra datatables support?
and that is my ref js that i`m using
<script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
I think maybe I misunderstood the problem. Are you having a problem with the
lengthMenu
or a problem with the select options for the column search?When is this used? Is this search resulting on only the current page being available?
Depends on where and what the problem is.
Can you post a link to your page or a test case replicating the issue so we can take a look?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
kindly be noted the below screen shot as Iam trying to get (Admin, Editor and User) in the search options but it show (User and Editor only).
Dear Kevin thank you for your fast respond and sorry my comment may be deleted by mistake so i was tell that i cannot use live.datatables.net as i using in my blade file
{!! $dataTable->scripts() !!}
and{!! $dataTable->table() !!}
and the below is my whole code for UsersDataTable.php
The code in your
initComplete
option builds the select list based on the data in that column of the table. Specifically this code:Do you have
Admin
in that column?Kevin
Yes I have with the page No.1 with user No.1 as the option list just get the current page not all pages. on the another side the admin will be shown if i change the order by or remove lengthMenu to show all items in 1 page.
thanks for trying helping me and i hope find good idea to solve this issue.
Since you are not using server side processing Datatables will contain all of the rows that are at the client. Look at the browser's network inspector tool to see how many rows are retrieved when the page loads.
Kevin
The rows are retrieved is only 10 from 0: Object to 9: Object according to Show 10 entries for each page.
That looks like Datatables server side processing where the server script only returns the number of rows for the page. So you have only 10 rows at the client. The code to build the select will only build the selects using the data in the client.
One option is to return the select options for all the rows on the first draw (
draw: 1
) from the server script. You can use that to load the search options. It will require modifying your server script.Another option is to use a non-server side processing server script so all the rows are returned to the client.
Kevin
sorry Kevin i don't got it. may be the sample guy like me can't get that great explain.
could you get example for one option that you mentioned?
Either of those options would require changes to your server script which I think you said is provided by Yajya Datatables. You will need to contact them to learn how to change their script to support your needs.
Kevin
Ok i will contact them.
Thank you Kevin
If all you want is to have those three search optoins you can manually create the search options for that column. Your other column searches will only contain the options available on the page.
Kevin
I got what you mean but my be i will need to add some options in future so it would be better to get the options dynamically.
Thanks Kevin