我有一个带有来自远程源的数据的引导表,但我找不到如何添加数据。 这是我的源数据:
Error Code: 1148. The used command is not allowed with this MySQL version.
但我希望如此:
$ajax[] = array(
"qta" => $row['qta'],
"name" => $row['name'],
"description" => $row['description']
);
为了让我的表格行像:
$ajax[] = array(
"id" => $row['id'], //123
"qta" => $row['qta'],
"name" => $row['name'],
"description" => $row['description']
);
我怎么能实现这个目标?也许有些回应哈德勒?我对BS Table很新。
答案 0 :(得分:1)
HTML表格
<table id="data" class="display table table-striped table-bordered">
<thead>
<tr>
<th>Row 1</th>
<th>Row 2</th>
<th>Row 3</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
服务器端
//List list = new LinkedList();
rs1 = s1.executeQuery("select * from somewhere");
obj = new JSONObject();
obj.put("row1", rs1.getString("rowfromdb1"));
obj.put("row2", rs1.getString("rowfromdb2"));
obj.put("row3", rs1.getString("rowfromdb3"));
//list.add(obj);
//return obj;
//return list
用于填写数据的JavaScript
//settings for your datatable
$(document).ready(function() {
$('#data').DataTable({
"columns": [{
"data": "row1",
"width": "30%"
}, {
"data": "row2",
"width": "30%"
}, {
"data": "row3",
"width": "40%"
}]
});
});
//ajax call which fill up your table on load of your page/change value of some object
$.ajax({
type: "GET",
url: "myScript",
data: "param1=" + value,
success: function(msg) {
$('#data').dataTable().fnClearTable();
$('#data').dataTable().fnAddData(
JSON.parse(msg.trim())
);
}
}
});
希望它可以帮到你