简体   繁体   中英

Refresh Datatable through AJAX call Laravel

i'm using Laravel Datatables 6.0 and jQuery, i want to do something which should be pretty simple, i have a list of signs for different people.

在此处输入图片说明

Like that and what i want, is to simply be able to (when i click one of those columns) filter the result set so that the only results returned are the ones where the Sign matches the one that was clicked.

So if you click "Tauro" you only get "Tauros", so on... how can this be achieved in jQuery Datatables using the Laravel Datatables package for Laravel?

So i managed to kinda figure it out, my solution ended being as follows:

        $(document).on('click', '.user-sign', function(e) {
            var sign = $(e.target).text();

            var table = $(".dataTable").DataTable();

            table.column( 6 )
                .search( sign )
                .draw();
        });

So i click the .user-sign and get the Text which indicates which Sign i want to query by. I get a reference to the DataTable (note the Capital D) and i tell it to query column 6 (where my signs are in the raw HTTP request) and search by the Sign name i've retrieved. Then finally i tell it to redraw the table....

Not pretty but far less code than any other solution i've seen so far on the Internet. Hope this helps someone, if you guys have something to add or reasons why this should not be done go ahead and let me know. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM