Error Undefined index: draw, start, lenght, order, column, search, allcount
Error Undefined index: draw, start, lenght, order, column, search, allcount
alvinkhan
Posts: 2Questions: 1Answers: 0
hi, i want to ask how to make server side datatables using costum filter on codeigniter.
this my model.php:
function getUsers($postData = null)
{
$response = array();
$draw = isset($postData['draw']);
$start = isset($postData['start']);
$rowperpage = isset($postData['length']); // Rows display per page
$columnIndex = isset($postData['order'][0]['column']); // Column index
$columnName = isset($postData['columns'][$columnIndex]['data']); // Column name
$columnSortOrder = isset($postData['order'][0]['dir']); // asc or desc
$searchValue = isset($postData['search']['value']); // Search value
// Custom search filter
$searchDepartement = $postData['searchDepartement'];
$searchCategory = $postData['searchCategory'];
$searchMERGE_ITEM = $postData['searchMERGE_ITEM'];
## Search
$search_arr = array();
$searchQuery = "";
if ($searchValue != '') {
$search_arr[] = " (departement like '%" . $searchValue . "%' or
category like '%" . $searchValue . "%' or
MERGE_ITEM like'%" . $searchValue . "%' ) ";
}
if ($searchDepartement != '') {
$search_arr[] = "departement='" . $searchDepartement . "' ";
}
if ($searchCategory != '') {
$search_arr[] = "category='" . $searchCategory . "' ";
}
if ($searchMERGE_ITEM != '') {
$search_arr[] = "MERGE_ITEM like '%" . $searchMERGE_ITEM . "%' ";
}
if (count($search_arr) > 0) {
$searchQuery = implode(" and ", $search_arr);
}
## Total number of records without filtering
$percobaan = "SELECT
TCS.departement,
TCS.category,
m.mnth AS CURR_MONTH,
MI.SIZCA0,
MI.CHNCA0,
MI.TAPCA0,
CONCAT(MI.SIZCA0,' ',MI.CHNCA0,MI.TAPCA0) AS MERGE_ITEM,
COALESCE(SUM(CASE
WHEN BE.DFROM IN ('SEWING', 'WEAVING', 'FORMING', 'DYE', 'HSM', 'INSPECTION', 'WOVEN') AND BE.DFROM = BE.DTO
THEN BE.QTY
END), 0.00) AS TOTAL_LOSS_PROSES,
COALESCE(SUM(CASE
WHEN DFROM != 'SEWING' THEN QTY
WHEN DFROM != 'WEAVING'THEN QTY
WHEN DFROM != 'FORMING'THEN QTY
WHEN DFROM != 'DYE'THEN QTY
WHEN DFROM != 'HSM'THEN QTY
WHEN DFROM != 'INSPECTION'THEN QTY
WHEN DFROM != 'WOVEN'THEN QTY
ELSE 0.00
END), 0.00) AS TOTAL_LOSS_SEMUA
FROM tbl_category_sewing TCS
CROSS JOIN (
SELECT '2022-04' AS mnth
UNION ALL
SELECT '2022-05'
UNION ALL
SELECT '2022-06'
UNION ALL
SELECT '2022-07'
UNION ALL
SELECT '2022-08'
) AS m
LEFT OUTER JOIN
B_ENTRYLOSS BE ON TCS.category = BE.LOSSCAT AND FORMAT(BE.DT, 'yyyy-MM') = m.mnth
LEFT OUTER JOIN
masteritem MI ON BE.ITEMCD = MI.ITMCA0
WHERE departement = 'WEAVING'
GROUP BY TCS.departement, TCS.category, m.mnth, MI.SIZCA0, MI.CHNCA0, MI.TAPCA0, CONCAT(MI.SIZCA0,' ',MI.CHNCA0,MI.TAPCA0)
ORDER BY category ASC, CURR_MONTH ASC, SIZCA0 ASC;";
$this->db->select('count(*) as allcount');
$records = $this->db->query($percobaan)->result();
$totalRecords = $records[0]->allcount;
## Total number of record with filtering
$percobaan = "SELECT
TCS.departement,
TCS.category,
m.mnth AS CURR_MONTH,
MI.SIZCA0,
MI.CHNCA0,
MI.TAPCA0,
CONCAT(MI.SIZCA0,' ',MI.CHNCA0,MI.TAPCA0) AS MERGE_ITEM,
COALESCE(SUM(CASE
WHEN BE.DFROM IN ('SEWING', 'WEAVING', 'FORMING', 'DYE', 'HSM', 'INSPECTION', 'WOVEN') AND BE.DFROM = BE.DTO
THEN BE.QTY
END), 0.00) AS TOTAL_LOSS_PROSES,
COALESCE(SUM(CASE
WHEN DFROM != 'SEWING' THEN QTY
WHEN DFROM != 'WEAVING'THEN QTY
WHEN DFROM != 'FORMING'THEN QTY
WHEN DFROM != 'DYE'THEN QTY
WHEN DFROM != 'HSM'THEN QTY
WHEN DFROM != 'INSPECTION'THEN QTY
WHEN DFROM != 'WOVEN'THEN QTY
ELSE 0.00
END), 0.00) AS TOTAL_LOSS_SEMUA
FROM tbl_category_sewing TCS
CROSS JOIN (
SELECT '2022-04' AS mnth
UNION ALL
SELECT '2022-05'
UNION ALL
SELECT '2022-06'
UNION ALL
SELECT '2022-07'
UNION ALL
SELECT '2022-08'
) AS m
LEFT OUTER JOIN
B_ENTRYLOSS BE ON TCS.category = BE.LOSSCAT AND FORMAT(BE.DT, 'yyyy-MM') = m.mnth
LEFT OUTER JOIN
masteritem MI ON BE.ITEMCD = MI.ITMCA0
WHERE departement = 'WEAVING'
GROUP BY TCS.departement, TCS.category, m.mnth, MI.SIZCA0, MI.CHNCA0, MI.TAPCA0, CONCAT(MI.SIZCA0,' ',MI.CHNCA0,MI.TAPCA0)
ORDER BY category ASC, CURR_MONTH ASC, SIZCA0 ASC;";
$this->db->select('count(*) as allcount');
if ($searchQuery != '')
$this->db->where($searchQuery);
$records = $this->db->query($percobaan)->result();
$totalRecordwithFilter = $records[0]->allcount;
## Fetch records
$percobaan = "SELECT
TCS.departement,
TCS.category,
m.mnth AS CURR_MONTH,
MI.SIZCA0,
MI.CHNCA0,
MI.TAPCA0,
CONCAT(MI.SIZCA0,' ',MI.CHNCA0,MI.TAPCA0) AS MERGE_ITEM,
COALESCE(SUM(CASE
WHEN BE.DFROM IN ('SEWING', 'WEAVING', 'FORMING', 'DYE', 'HSM', 'INSPECTION', 'WOVEN') AND BE.DFROM = BE.DTO
THEN BE.QTY
END), 0.00) AS TOTAL_LOSS_PROSES,
COALESCE(SUM(CASE
WHEN DFROM != 'SEWING' THEN QTY
WHEN DFROM != 'WEAVING'THEN QTY
WHEN DFROM != 'FORMING'THEN QTY
WHEN DFROM != 'DYE'THEN QTY
WHEN DFROM != 'HSM'THEN QTY
WHEN DFROM != 'INSPECTION'THEN QTY
WHEN DFROM != 'WOVEN'THEN QTY
ELSE 0.00
END), 0.00) AS TOTAL_LOSS_SEMUA
FROM tbl_category_sewing TCS
CROSS JOIN (
SELECT '2022-04' AS mnth
UNION ALL
SELECT '2022-05'
UNION ALL
SELECT '2022-06'
UNION ALL
SELECT '2022-07'
UNION ALL
SELECT '2022-08'
) AS m
LEFT OUTER JOIN
B_ENTRYLOSS BE ON TCS.category = BE.LOSSCAT AND FORMAT(BE.DT, 'yyyy-MM') = m.mnth
LEFT OUTER JOIN
masteritem MI ON BE.ITEMCD = MI.ITMCA0
WHERE departement = 'WEAVING'
GROUP BY TCS.departement, TCS.category, m.mnth, MI.SIZCA0, MI.CHNCA0, MI.TAPCA0, CONCAT(MI.SIZCA0,' ',MI.CHNCA0,MI.TAPCA0)
ORDER BY category ASC, CURR_MONTH ASC, SIZCA0 ASC;";
if ($searchQuery != '')
$this->db->where($searchQuery);
$this->db->order_by($columnName, $columnSortOrder);
$this->db->limit($rowperpage, $start);
$records = $this->db->query($percobaan)->result();
$data = array();
foreach ($records as $record) {
$data[] = array(
"departement" => $record->departement,
"category" => $record->category,
"MERGE_ITEM" => $record->MERGE_ITEM,
"TOTAL_LOSS_PROSES" => $record->TOTAL_LOSS_PROSES,
"TOTAL_LOSS_RETURN" => $record->TOTAL_LOSS_SEMUA - $record->TOTAL_LOSS_PROSES,
"TOTAL_LOSS_SEMUA" => $record->TOTAL_LOSS_SEMUA
);
}
## Response
$response = array(
"draw" => intval($draw),
"iTotalRecords" => $totalRecords,
"iTotalDisplayRecords" => $totalRecordwithFilter,
"aaData" => $data
);
return $response;
}:
please help me
Answers
this my controller.php
this is my view:
this my html script:
DataTables uses a GET request by default, but your server-side script appears to be looking for POST data.
Add:
to your
ajax
object.Allan