如果api中的数据为空,如何隐藏数据表?

时间:2018-12-25 09:44:19

标签: javascript jquery html ajax datatables

我有一个表来显示数据表数据,但是有时数据表为空,在这种情况下我需要隐藏数据表。但是,即使没有数据,也会显示具有空数据的数据表。如何隐藏数据表,仅在有数据时才显示数据表?

加载数据表的代码

var table2 = $('#nepal').DataTable({
        "processing" : true,
        "scrollY": 100,
        "scrollX": true,
        "ajax" : {
            "url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
            dataSrc : ''
        },
        "columns" : [ {
            "data" : "selectionId"
        }, {
            "data" : "selectionDate"
        }, {
            "data" : "selectedBy"
        }, {
            "data" : "eximPanNo"
        }, {
            "data" : "eximPanName"
        }, {
            "data" : "eximPanAddr"
        }, {
            "data" : "eximPanPhone"
        }, {
            "data" : "selectionType"
        },{
            "data" : "auditorGroupName"
        },{
            "data":"selectionAudit[0].assignFromDate",
            mRender: function(data,type,row){
                //data means id 
                var str='';
                str += '<a  class="fa fa-pencil" id="edit1"></a>';

                str += '<a class="fa fa-trash" id="delete"></a>';

                return str;
            }
        } ]
    });

用于显示数据的表

 <table id="nepal" class="table table-bodered">

          <thead>
            <tr>
              <th>Selection No</th>
              <th>SelectionDate</th>
              <th>SelectedBy</th>
              <th>PanEximNumber</th>
              <th>Name</th>
              <th>Address</th>
              <th>PhoneNumber</th>
              <th>SelectionType</th>
               <th>Group Desc</th> 
               <th>Action</th>  


            </tr>
          </thead>
          <tbody>

          </tbody>

        </table>

0 个答案:

没有答案