こんにちは、私はajaxからデータテーブルの読み込みがあります。
ある条件に対して行の色を変更する必要があります。このdatatable ajaxの色PHPの条件に基づいて行の変更
$(document).ready(function() {
var dataTable = $('#example').DataTable({
processing: true,
serverSide: true,
ajax: "ajax.php" // json datasource
});
});
それが動作ajax.php
while($row=mysqli_fetch_array($query)) { // preparing an array
$nestedData=array();
$nestedData[] = $i;
$nestedData[] = $row["id"];
$nestedData[] = $row["name"];
$nestedData[] = $row["status"];
$data[] = $nestedData;
$i++;
}
$json_data = array(
"draw" => intval($requestData['draw']), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval($totalData), // total number of records
"recordsFiltered" => intval($totalFiltered), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
でこの
<table id="example" >
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
</table>
のようなHTMLが、私は何を必要とするような
スクリプトは、状況に応じて、行の色を変更することです。
ステータスが== 1の場合は黄色、ステータスが== 2の場合は赤、ステータスが== 3の場合は赤、このタイプのフォーマットではこのテーブル行の色を追加します。次のように
データテーブルのロード後は、各ループ機能を使用することができますし、それぞれの行で、ステータス列の値を取得し、それが列の値ですチェックして、あなたの状態を比較し、それが満たされます色を変更しました – Divyesh