我无法弄明白这一点,他们的API非常令人困惑。
我有一个表格,显示几何特征的表格数据,所以我想在行数据中保存坐标。
我需要一种方法来检索这个坐标,例如,当用户点击该行时。
我正在努力实现的例子:
{"name": "xxx"}
我认为存储在隐藏列中并不理想,因为对于多边形类型,坐标可能会非常大。
我是DataTables的新手,并且对API非常困惑,任何关于如何更好地组织/执行我的概念的建议都非常受欢迎。
答案 0 :(得分:1)
似乎你应该工作的东西。我为你准备了一个小例子: http://live.datatables.net/rikofefu/1/edit
它添加了一个额外的geometry
对象的行。选择该行,然后单击Show selected data
按钮。控制台将显示完整行和几何对象。
我使用Select extension获取所选行。
答案 1 :(得分:1)
HTML
<table>
<thead>
<tr>NAME</tr>
<tr>COLOR</tr>
<tr></tr>
</thead>
</table>
JS
const dt = $('table').DataTable({
columns: [
{data: null},
{data: null},
{data: null}
],
// This makes the row clickable, where you can get data later
"createdRow": function (row, data, dataIndex) {
var tds = $(row).find("td");
$.each(tds, function (key, value) {
$(value).attr("onclick", "see_the_data(this)");
}
},
// this hides the coordinate column from view
"columnDefs": [
{
"targets": 2,
"visible": false
}
]
});
dt.row.add({
COLOR: "Red",
NAME: "Point1",
//Invalid parameter error
geometry: {
type: "point",
coordinates: [1, 1]
}
});
function see_the_data(e) {
console.log("the data is ", e); // you can then go further as you need
}