单击按钮无法加载数据表

时间:2018-02-22 09:33:25

标签: datatables

我试图在点击数据表外的按钮时加载数据表。

下面是我的代码

  $('#buttonToLoadDatatable').on('click', function() {
        $.ajax({
                type:        "GET",
                url:"../fhParser/fhParser/downloadAndParseResume/v1",           
        }).done(function (result) {
            var table = $('#example').DataTable( {
            "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-
             12 hidden-xs'l>r>"+
                    "t"+
                    "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
                "oLanguage": {
                    "sSearch": '<span class="input-group-addon"><i 
                    class="glyphicon glyphicon-search"></i></span>'
                },                      
                "bDestroy": true,
                "data":result,
                "iDisplayLength": 15,
              /**this portion was because I have a collapsible rows**/
                "columns": [ 
                            {
                                "class":          'details-control',
                                "orderable":      false,
                                "data":           null,
                                "defaultContent": ''
                            },
                            {  "data":"email"  }
                        ],
                rowCallback: function (row, data) {},
                filter: false,
                info: false,
                ordering: false,
                processing: true,
                retrieve: true,  

                "fnDrawCallback": function( oSettings ) {
                   runAllCharts()
                }
               // rowCallback: function (row, data) {}
            } );
             console.log( result );

            }).fail(function (jqXHR, textStatus, errorThrown) { 
            });
    });

当我在浏览器控制台中打印该值时,它会正确显示为 {&#34; email&#34;:&#34; tryingandtest@gmail.com"},但它没有显示在数据表中

控制台或后端也没有错误

1 个答案:

答案 0 :(得分:0)

可以将代码替换为

$('#buttonToLoadDatatable').on('click', function() {
        $.ajax({
                type:        "GET",
                url:"../fhParser/fhParser/downloadAndParseResume/v1",           
        }).done(function (result) {
            var table = $('#example').DataTable( {
            "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-
             12 hidden-xs'l>r>"+
                    "t"+
                    "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
                "oLanguage": {
                    "sSearch": '<span class="input-group-addon"><i 
                    class="glyphicon glyphicon-search"></i></span>'
                },                      
                "bDestroy": true,
                "data":result.data,
                "iDisplayLength": 15,
              /**this portion was because I have a collapsible rows**/
                "columns": [ 
                            {
                                "class":          'details-control',
                                "orderable":      false,
                                "data":           null,
                                "defaultContent": ''
                            },
                            {  "data":"email"  }
                        ],
                rowCallback: function (row, data) {},
                filter: false,
                info: false,
                ordering: false,
                processing: true,
                retrieve: true,  

                "fnDrawCallback": function( oSettings ) {
                   runAllCharts()
                }
               // rowCallback: function (row, data) {}
            } );
             console.log( result );

            }).fail(function (jqXHR, textStatus, errorThrown) { 
            });
    });

并检查是否有效

FYI将"data":result更改为"data":result.data