Обработка DataTable на стороне сервера по запросу соединения таблицы в CodeigniterJquery

Программирование на jquery
Ответить
Anonymous
 Обработка DataTable на стороне сервера по запросу соединения таблицы в Codeigniter

Сообщение Anonymous »

Я пытался работать с таблицей данных на стороне сервера, я успешно реализовал таблицу данных при работе с одной таблицей, однако теперь я пытаюсь найти способ работы с несколькими таблицами с использованием запроса на соединение. И я знаю, что мне нужно предоставить Limit, Order_by и фильтр для сортировки данных, но я немного сбит с толку и не могу работать над запросом соединения вместе с таблицами данных, поскольку я все еще учусь и знакомлюсь с Codeigniter и таблицами данных. Как я могу ограничить и фильтровать данные, извлекаемые из нескольких таблиц с помощью объединений, здесь. Любая помощь или предложение очень ценятся, ребята.
Это мой контроллер

function get_form_ajax() {
$requestData= $_REQUEST;

$columns = array(
0 => 'Id',
1 => 'CustomerName',
2 => 'CustomerNumber',
3 => 'ConsumerName',
4 => 'ConsumerNumber',
5 => 'Profit Center',
6 => 'Month',
7 => 'Date',
8 => 'OpeningBalance',
9 => 'Recieve',
10 => 'Sales,
11 => 'ClosingBalance'
);

$where ="";

if(!empty($sales_offices_id)){
$where = "where sales_offices.id = '$sales_offices_id'";
}
else{
$where .= "";
}

$sql = "select sales_offices.name as ProfitCenter, transactions.id as Id, distributors.name as CustomerName , distributors.code as CustomerNumber, customers.firstname as ConsumerName,customers.mobile as ConsumerNumber, customers.id as ConsumerId ,(case when transactions.payment_type='Credit' then transactions.amount else 0 end) as Receive, transactions.balance_before as OpeningBalance, (case when transactions.payment_type='Debit' then transactions.amount else 0 end) as Sales, transactions.balance_after as ClosingBalance,MONTHNAME(transactions.payment_date) as Month, Date(transactions.payment_date) as Date
FROM `transactions`
INNER JOIN addresses ON transactions.c_id = addresses.c_id
INNER JOIN customers ON customers.id = addresses.c_id
INNER JOIN distributors ON distributors.id = addresses.distributor_id
INNER JOIN sales_offices ON distributors.sales_office_id = sales_offices.id
$where ORDER BY distributors.id , customers.id , transactions.id ASC";

$query = $this->db->query($sql);

$arr = $query->result_array();

$this->db->order_by( $columns[$requestData['order'][0]['column']], $requestData['order'][0]['dir']);

$this->db->limit( $requestData['length'], $requestData['start']);

$totalData = $this->db->count_all();

$totalFiltered = $query->num_rows();

$data = array();

for( $i = 0 ; $i < count($arr) ; $i++ )
{
$nestedData=array();

$nestedData[] = $i + 1;
$nestedData[] = $arr[$i]['CustomerName'];
$nestedData[] = $arr[$i]['CustomerNumber'];
$nestedData[] = $arr[$i]['ConsumerName'];
$nestedData[] = $arr[$i]['ConsumerNumber'];
$nestedData[] = $arr[$i]['ProfitCenter'];
$nestedData[] = $arr[$i]['Month'];
$nestedData[] = $arr[$i]['Date'];
$nestedData[] = $arr[$i]['OpeningBalance'];
$nestedData[] = $arr[$i]['Receive'];
$nestedData[] = $arr[$i]['Sales'];
$nestedData[] = $arr[$i]['ClosingBalance'];

$id = $arr[$i]['Id'];
$customer_name = $arr[$i]['CustomerName'];
$customer_no = $arr[$i]['CustomerNumber'];
$consumer_name = $arr[$i]['ConsumerName'];
$consumer_no = $arr[$i]['ConsumerNumber'];
$proft_center = $arr[$i]['ProfitCenter'];
$month = $arr[$i]['Month'];
$date = $arr[$i]['Date'];
$opening_bal = $arr[$i]['OpeningBalance'];
$recieve = $arr[$i]['Receive'];
$sales = $arr[$i]['Sales'];
$closing_bal = $arr[$i]['ClosingBalance'];
$data[] = $nestedData;
}

$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);
echo json_encode($json_data);
}


Вот мой Аякс

function table_datatable(page_limit){
var dataTable = $('#myTable').DataTable( {
"processing": false,
"serverSide": true,
"dom": 'lBfrtip',
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'excel',
'pdf',
'print']
}
],
"lengthMenu": [[5, 10, 15, 20, 25, 30], [5, 10, 15, 20, 25, 30]],
"pageLength": 10,
"order": [[ 0, "desc" ]],
"destroy": true,
"ajax":{
url : "get_form_ajax", // json datasource
type: "post", // method , by default get
error: function(){ // error handling

}
}
});
}


Подробнее здесь: https://stackoverflow.com/questions/616 ... odeigniter
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»