hermawanramadhan / CodeIgniter4-DataTables

MIT License
93 stars 38 forks source link

Limit query is not working with Datatable #30

Open DhPandya opened 1 year ago

DhPandya commented 1 year ago

Describe the bug Suppose I want to display the latest 10 orders on the dashboard and I added a limit(10) to my query then it's now working with the datatables. It is always showing all records instead of the limit. It always takes the length of the datatable rendered Dropdown. Here it should work if I'm limiting the results to 10 then it should show only 10 records.

Your code

$builder = $this->order_model->select('orders.id,company_name,order_no,order_datetime,empty_date_called,customer_id,booking_no,steamship_id,container_no,size_id,pickup_return_location,order_status,terminate,steamships.name as steamship_name,size_id,size,is_void,(CASE WHEN order_type=3 THEN "Domestic" WHEN order_type=2 THEN "Export" WHEN order_type=1 THEN "Import" WHEN order_type=4 THEN "Trailer" ELSE "N/A" END) as order_type_text,chassis,chassis_id')
            ->join('customers', 'customers.id=orders.customer_id', 'left')
            ->join('steamships', 'steamships.id=orders.steamship_id', 'left')
            ->join('containersizes', 'containersizes.id=orders.size_id', 'left')
            ->join('(SELECT id,chassis from ' . db_prefix() . 'chasses) as tblchasses', 'tblchasses.id=orders.chassis_id', 'left')
            ->limit(10);

$datatable = DataTable::of($builder);
return $datatable->toJson(true);

Screenshots If applicable, add screenshots to help explain your problem.

Version (please complete the following information):