Search code examples
jsonajaxbootstrap-table

Method 'load' does not work bootstrap-table


I'm trying to load data and popular a table bootstrap-table through an ajax call, but it does not work with the load method. Trying the data method works normally.

the method is not starting, it also does not display that no result was found

Table

<table id="table-anexo" class="table table-striped table-hover display" style="width:100%">
    <thead>
        <tr>
             <th data-field="id"><span>DOCUMENTO</span></th>
             <th data-field="tipo"><span>TIPO</span></th>
             <th data-field="dt_anexo"><span>DATA ANEXO</span></th>
         <!--<th data-field="acao" data-formatter="" data-events="" ><span>AÇÃO</span></th>-->
        </tr>
   </thead>
</table>

Function AJAX

function get_anexo_ajax(metodo, editando_id) {
    var ticket_id = editando_id;
    $.ajax({
        type: 'POST',
        data: {ticket_id : ticket_id},
        url: 'ticket/get_anexo_all',
        success: (function (data) {
            console.log(data.anexo);          
            //$('#table-anexo').bootstrapTable({ data: data.anexo });
            //$('#table-anexo').bootstrapTable('refresh')
            $('#table-anexo').bootstrapTable('load', data.anexo);
        }),
    });
}

Data JSON

{"anexo":[{"id":"1","tipo":"jpg","dt_anexo":"2018-08-01 11:09:28","mensagem_id":"2","ticket_id":"1"}]}

Solution

  • I think data is the invalid format. And Set data-toggle="table" on a normal table. I tested, it run Ok. You can try:

    <table id="table-anexo" data-toggle="table" class="table table-striped table-hover display" style="width:100%">
    
        var obj = JSON.parse(data);
        $('#table-anexo').bootstrapTable('load', obj.anexo);