我正在使用jQuery DataTables,并且需要一种在数据表中的列上呈现单选按钮的方法,该呈现必须通过JavaScript而不是来自JSON结果。

最佳答案



您可以使用 render 选项为单元格生成内容。

考虑以下示例:

var table = $('#example').DataTable({
    ajax: 'https://api.myjson.com/bins/1us28',
    order: [[1, 'asc']],
    columnDefs: [
        {
            targets: 0,
            searchable: false,
            orderable: false,
            render: function(data, type, full, meta){
               if(type === 'display'){
                  data = '<input type="radio" name="id" value="' + data + '">';
               }

               return data;
            }
        }
    ]
});

演示

有关代码和演示,请参见this jsFiddle

10-05 20:49
查看更多