[英]Creating a combobox in a jquery datatable
I am using the following to create a datatable. 我正在使用以下内容创建数据表。
mydata = [{
"id": "1",
"name": "daniel",
"age": "28",
"position": "accountant",
"status": "A"
}, {
"id": "2",
"name": "jack",
"age": "55",
"position": "architect",
"status": "R"
}];
$('#myTable').dataTable({
"aaData": mydata,
"aoColumns": [{
"mDataProp": "id"
,{
"mDataProp": "name"
}, {
"mDataProp": "age"
}, {
"mDataProp": "position"
},
{
"mDataProp": "status"
}]
});
Now I need to create a combobox for the column "status" (Options: D, L, A, R) having each status with a separate ID (using ID from the "id" column). 现在,我需要为“状态”列(选项:D,L,A,R)创建一个组合框,其每个状态都有一个单独的ID(使用“ id”列中的ID)。 As a start I used the mRender function to create a combobox like:
首先,我使用mRender函数创建了一个组合框,如下所示:
{
"mDataProp": "status",
mRender: function(oObj){
return '<select id = "status">'+'<option value = "D"> D </option>'+'<option value = "L"> L </option>'+'<option value = "A"> A </option>'+'<option value = "R"> R </option>'+'</select>';
}
}
This just creates a simple combobox but I want to know as to how would I assign each option with the "id" column. 这只是创建一个简单的组合框,但我想知道如何分配带有“ id”列的每个选项。 Any suggestions?
有什么建议么?
You can get your JSON file from a different absolute URL (eg, www.example.com/files/myJson.JSON
) or from a relative URL (eg, /files/myJson.JSON
) 您可以从其他绝对URL(例如,
www.example.com/files/myJson.JSON
/ /files/myJson.JSON
)或相对URL(例如,/ /files/myJson.JSON
)获取JSON文件。
The rest is pretty simple. 其余的非常简单。
$(document).ready(function() {
$.getJSON( "<<LOCATION OF YOUR FILE>>", function( data ) {
var mydata = data;
$('#myTable').dataTable({
"aaData": mydata,
"columns": [{
"data": "name"
}, {
"data": "age"
}, {
"data": "position"
}]
});
});
});
Keep your HTML as is. 保持HTML原样。 Note that I simplified your Datatables formatting, as you were using labels from an older version.
请注意,由于您使用的是旧版本的标签,因此我简化了数据表的格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.