Laravel DataTables Nested relationship search not working


Hi i am working on a Laravel project and setup relationship between the following tables

permissions table

permissions_modules

public function moduleAddPermissions(Request $request, $id)
{

    $model = PermissionsModule::with('module_permissions')->find($id);

    if ($request->ajax()) {
    

        return Datatables::of($model ? [$model] : [])

            ->addIndexColumn()

            ->make(true);
    }

    return view('admin.users.permissions.module_permissions_create', compact('model'));
}

what i am trying to do here is open a Module detail page where i have a data table showing a list of all the permissions for that specific Module using datatable which is working fine and here is my javascript.

$('#module-permissions-table').DataTable({


            pageLength: 25,
            lengthMenu: [
                [10, 25, 50, 100, 250, 500],
                [10, 25, 50, 100, 250, 500]
            ],
            aaSorting: [],
            language: {
                emptyTable: "No data available in table",
                info: "Showing _START_ to _END_ of _TOTAL_ records",
                infoEmpty: "Showing 0 to 0 of 0 entries",
                infoFiltered: "(filtered from _MAX_ total entries)",
                infoPostFix: ".",
                thousands: ",",
                lengthMenu: "_MENU_ records per page",
                loadingRecords: "Loading...",
                processing: "Processing...",
                search: "Search Permission: ",
                zeroRecords: "No matching records found",
                paginate: {
                    first: "First",
                    last: "Last",
                    next: "Next",
                    previous: "Previous"
                },
                aria: {
                    sortAscending: ": activate to sort column ascending",
                    sortDescending: ": activate to sort column descending"
                }
            },

            responsive: true,
            processing: true,
            serverSide: true,




            ajax: {

                url: url,
               
            },

            columns: [



                {

                    data: 'module_permissions',

                    name: 'module_permissions.name',

                    render: function(data, type, row) {
                        var txt = '<div class="row">';
                        data.forEach(function(permissions) {




                            txt += '<div class="switch switch-success d-inline col-lg-3">
                                    <input type="checkbox" id="permission-' + permissions.id + '" value="' +
                                permissions.id + '" name="permissions[]" checked ">
                                     <label for="permission-' + permissions.id + '" class="cr" data-toggle="tooltip" title="Toogle To Delete This Permission!"></label>
                                       <label class="ml-2">' + permissions.name + '</label>
                                                                            </div>';


                        });
                        txt += '</div>'
                        return txt;
                    }
                },


            ],




        });

but my problem is that i am not able to search this column so if anyone can help me with this.
Sorry for the typo and english. whatever i type in the search field it return no record find.

Thanks

Source: JavaSript – Stack Overflow

September 3, 2021
Category : News
Tags: datatable | javascript | laravel | yajra-datatable

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.