【问题标题】:how get data from selected row datatable.js如何从选定的行 datatable.js 获取数据
【发布时间】:2018-08-16 02:45:07
【问题描述】:

这样我获取数据

  $(document).ready(function() {
$('#example').DataTable( {

    "ajax": {
      "method":"POST",
      "url":"exampleurl.php"
      },
      "columns":[
          {"data":"title"},
          {"data":"description"},
          {"defaultContent": "<button  id='show-info' data-toggle='modal' data-target='#show-modal' class='btn btn-primary'>show</button>"}
      ]
} );

 $('#example tbody').on( 'click', 'button', function () {


  console.log( table.row( this ).data() );

      });
});

我已经看到了他们建议使用这个的答案

table.row( this ).data() 

但不适合我

【问题讨论】:

    标签: jquery datatable datatables


    【解决方案1】:

    为DataTable实例化设置一个变量,并将table.row( this ).data()改为table.row( $(this).parents('tr') ).data()

    $(document).ready(function() {
        var table = $('#example').DataTable( {
            "ajax": {
                "method":"POST",
                "url":"exampleurl.php"
            },
            "columns":[
                {"data":"title"},
                {"data":"description"},
                {"defaultContent": "<button  id='show-info' data-toggle='modal' data-target='#show-modal' class='btn btn-primary'>show</button>"}
            ]
        } );
    
        $('#example tbody').on( 'click', 'button', function () {
    
    
            console.log(table.row( $(this).parents('tr') ).data());
    
        });
    });
    

    【讨论】:

    • 告诉我表没有定义
    • 您是如何获取数据的? @MichelNovellino
    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多