我正在尝试使用服务器端处理来填充jquery数据表。在php中,我使用mysql连接查询从两个表中获取数据。
我的查询如下:
$sQuery = "SELECT SQL_CALC_FOUND_ROWS u.user_id
, CONCAT(u.first_name, ' ', u.last_name)
, u.gender
, CONCAT(a.suburb, ', ', a.zip_code)
, u.date_registered
FROM users u
INNER JOIN user_addresses a ON a.user_id = u.user_id AND a.address_type = 1 ".$sWhere.$sOrder.$sLimit;
列数组是这样的:
$aColumns = array (
"u.user_id",
"CONCAT(u.first_name, ' ', u.last_name)",
"u.gender",
"CONCAT(a.suburb, ', ', a.zip_code)",
"u.date_registered"
);
我的问题是它的显示数据仅适用于第2和第4列。它为其他列提供了null
个值。
{
"sEcho": 1,
"iTotalRecords": "7",
"iTotalDisplayRecords": "7",
"aaData": [
[null, "Tharanga Kumara", null, "Wanniassa
, 2903", null],
[null, "dsfadsf fdaf", null, "Ashford, 5035", null],
[null, "fdafa dfdaf", null, "Wanniassa, 2903", null],
[null, "Dilani Kumari", null, "dfdaf, 34234", null],
[null, "Kamal Maduranga ", null, "Wanniassa, 2903", null],
[null, "Sampath Gunathilaka", null, "Eastern Suburbs Mc, 2004", null],
[null, "Kasun Sandaruwan", null, "Wanniassa, 2903", null]
]
}
更新 数据表代码:
.DataTable({
bAutoWidth: false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "includes/process_customer_datatable.php",
"aoColumnDefs": [{
"aTargets": [0],
"bSortable": false,
//"sTitle": "ip",
"sClass": "center",
"mRender": function (data, type, full) {
return '<label class="pos-rel">' +
'<input class="custom" type="checkbox">' +
'</label>';
}
},
{
"aTargets": [5], //Delete column
"mData": "0",
"mRender": function (data, type, full) {
return '<a href=' + 'index.php?customer=' + data + '>Delete</a>';
}
}
],
// "aoColumns": [
// { "bSortable": false },
// null,
// null,
// null,
// null,
// null,
// { "bSortable": false },
// ],
"aaSorting": [],
});
有谁能告诉我这是什么问题? 希望有人可以帮助我。
答案 0 :(得分:0)
您可以对从PHP返回的对象进行字符串化。使用带有空字符串的正则表达式替换空值,然后将字符串解析回JSON对象。
此处示例:
import cats.state.State
import cats.std.function._, cats.std.list._
import cats.syntax.traverse._
abstract class DepthFirstState[E, S] {
def build(elem: E): State[S, List[E]]
def go(start: E): State[S, List[E]] = for {
xs <- build(start)
ys <- xs.traverseU(go)
} yield start :: ys.flatten
}
class RangeSearchState extends DepthFirstState[Int, Int] {
def build(elem: Int): State[Int, List[Int]] =
State.get[Int].map(limit => if (elem < limit) List(elem + 1) else Nil)
}
val (state, result) = (new RangeSearchState).go(1).run(10000).run