Php 按其值为行背景添加颜色
我希望根据状态列的值更改行颜色, (状态上会有三个字中的一个,如:“已订购”、“已装运”、“已完成”) 这是我从网上找到的零开始编写的代码 这是我的密码:Php 按其值为行背景添加颜色,php,uitableview,background-color,Php,Uitableview,Background Color,我希望根据状态列的值更改行颜色, (状态上会有三个字中的一个,如:“已订购”、“已装运”、“已完成”) 这是我从网上找到的零开始编写的代码 这是我的密码: <div class="tabela"> <div class="table-responsive"> <table id="order_data" class="table table-bordered table-strip
<div class="tabela">
<div class="table-responsive">
<table id="order_data" class="table table-bordered table-striped">
<thead>
<tr>
<th>ID.</th>
<th>Date</th>
<th>Name</th>
<th>Description</th>
<th>Address</th>
<th>City</th>
<th>Phone</th>
<th>Status</th>
<th>Shipping</th>
<th>Value</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th colspan="9"><b>Total</b></th>
<th id="total_order"></th>
</tr>
</tfoot>
</table>
<br />
<br />
<br />
</div>
</div>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
var dataTable = $('#order_data').DataTable({
"processing" : true,
"serverSide" : true,
"order" : [],
"ajax" : {
url:"template/fetch.php",
type:"POST"
},
drawCallback:function(settings)
{
$('#total_order').html(settings.json.total);
},
});
});
</script>
身份证件
日期
名称
描述
地址
城市
电话
地位
航运
价值
全部的
$(文档).ready(函数(){
var dataTable=$('#订单_数据')。dataTable({
“处理”:对,
“服务器端”:正确,
“订单”:[],
“ajax”:{
url:“template/fetch.php”,
类型:“职位”
},
drawCallback:函数(设置)
{
$('#total_order').html(settings.json.total);
},
});
});
这也是我的收获:
<?php
//fetch.php
// Include config file
require_once "../config/configpdo.php";
$column = array('order_id', 'order_date', 'order_customer_name', 'order_item', 'order_address', 'order_city', 'order_number', 'order_value', 'order_ship', 'order_status');
$query = '
SELECT * FROM tbl_order
WHERE order_id LIKE "%'.$_POST["search"]["value"].'%"
OR order_date LIKE "%'.$_POST["search"]["value"].'%"
OR order_customer_name LIKE "%'.$_POST["search"]["value"].'%"
OR order_item LIKE "%'.$_POST["search"]["value"].'%"
OR order_address LIKE "%'.$_POST["search"]["value"].'%"
OR order_city LIKE "%'.$_POST["search"]["value"].'%"
OR order_value LIKE "%'.$_POST["search"]["value"].'%"
OR order_ship LIKE "%'.$_POST["search"]["value"].'%"
OR order_number LIKE "%'.$_POST["search"]["value"].'%"
OR order_status LIKE "%'.$_POST["search"]["value"].'%"
';
if(isset($_POST["order"]))
{
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY order_id DESC ';
}
$query1 = '';
if($_POST["length"] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connect->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();
$statement = $connect->prepare($query . $query1);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$total_order = 0;
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = $row["order_id"];
$sub_array[] = $row["order_date"];
$sub_array[] = $row["order_customer_name"];
$sub_array[] = $row["order_item"];
$sub_array[] = $row["order_address"];
$sub_array[] = $row["order_city"];
$sub_array[] = $row["order_number"];
$sub_array[] = $row["order_status"];
$sub_array[] = $row["order_ship"];
$sub_array[] = $row["order_value"];
$total_order = $total_order + floatval($row["order_value"]);
$data[] = $sub_array;
}
function count_all_data($connect)
{
$query = "SELECT * FROM tbl_order";
$statement = $connect->prepare($query);
$statement->execute();
return $statement->rowCount();
}
$output = array(
'draw' => intval($_POST["draw"]),
'recordsTotal' => count_all_data($connect),
'recordsFiltered' => $number_filter_row,
'data' => $data,
'total' => number_format($total_order, 2)
);
echo json_encode($output);
?>
我感谢你没有人帮忙,所以我花了好几天的时间从划痕中找到了解决办法。有一个想法是,如果建立了一个特定的单词,我在脚本上方插入了一个函数,则将行定位并冻结以插入一个类:
rowCallback: function( row, data, index ) {
if ( data[7] == "Ordered" ) {$(row).addClass('green');}
else if ( data[7] == "Shipped" ) {$(row).addClass('orange');}
else if ( data[7] == "Completed" ) {$(row).addClass('red');}
}
还必须通过在…内部插入像这样的css样式
<style>
.green{
background-color:#85e085 !important;}
.orange{
background-color:#ffb366 !important;}
.red{
background-color:#ff6666 !important;
}
</style>
格林先生{
背景色:#85e085!重要;}
.橙色{
背景色:#ffb366!重要;}
瑞德先生{
背景色:#ff6666!重要;
}
我张贴的答案可能有人有相同的问题,它可以帮助一点。
如果你需要任何属于这个的东西,请告诉我