【问题标题】:How to render radio button group with the jQuery DataTables如何使用 jQuery DataTables 呈现单选按钮组
【发布时间】:2015-10-18 11:34:13
【问题描述】:

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

【问题讨论】:

  • 请显示您的代码,即您如何初始化数据表以及您想要转换为单选按钮的 JSON。

标签: javascript jquery datatables datatables-1.10


【解决方案1】:

解决方案

您可以使用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

【讨论】:

  • 如何获取所有数据表页面的选定单选按钮值?我想获取每个页面的所有选定单选按钮值让我们假设在一个数组中
  • @MuhammadRizwan, answered your question.
猜你喜欢
  • 2013-08-28
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-09
相关资源
最近更新 更多