Skip to content

Serverside datatables #9

@hardikpoojara

Description

@hardikpoojara

When creating datatables to find data from database using serverside method of datatables then view of table is something like attached screenshot.

JS code
`
function loadDatatable() {
$('.serverside').DataTable({
serverSide: true,
ajax: "{{url('admin/entry/list-entries-datatables')}}",
lengthMenu: [[25, 100, -1], [25, 100, "All"]],
pageLength: 25,
columns: [
{ data: "check",name:"check" },
{ data: "id",name:"ID" },
{ data: "customer_id",name:"customer_id" },
{ data: "entry_type",name:"entry_type" },
{ data: "department",name:"department" }
]

            // other options
        });
    }

`

Controller
`
$entries = Entry::select(['id', 'customer_id', 'entry_type', 'department','total_amount']);

    if ($request->has('customer_id')) {
        $entries =$entries->where('customer_id', $request->customer_id);
    }
    $entries =$entries->with(['entryTypeDetails', 'departmentDetails', 'customer']);
    $entries =$entries->get();

    return Datatables::of($entries)->make(true);

`

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions