How can i display loading/processing message inside DataTable?

前端 未结 4 1126
野性不改
野性不改 2021-01-21 03:08

In my application i am using datatables.net

var ticketHistoryDataTable = $(\'#ticketHistoryData\').DataTable({ 
        paging: false,
        data: [],
                 


        
相关标签:
4条回答
  • 2021-01-21 03:53

    You can use dom option to show loading:

    $('#example').dataTable( {
      "dom": 'lrtip'
    } );
    

    "r" letter is related to show loading element.
    For more information refer to this link

    0 讨论(0)
  • 2021-01-21 03:55

    You can use a loader in your html. Position should be same as the table. How to add a loader in HTML

    or Message container: <div id="MessageContainer"></div> and Apply some CSS styles for good look and feel.

         $('#ticketHistoryData')
            .on( 'draw.dt', function () {
                console.log( 'Loading' );
              //Here show the loader.
              // $("#MessageContainer").html("Your Message while loading");
            } )
            .on( 'init.dt', function () {
                console.log( 'Loaded' );
               //Here hide the loader.
                // $("#MessageContainer").html("Your Message while load Complete");
            } )
            .DataTable({ 
                paging: false,
                data: [],
                searching: false,
                columns: [
                    { data: 'ticket_id'         ,   title: "Ticket Number" },
                    { data: 'transactiondate'   ,   title: "Date"          } 
                ]
         });
    

    For more go through Events of DataTable

    I think this might help you.

    You might show message

    0 讨论(0)
  • 2021-01-21 04:04

    When loading data from an Ajax source, you can use the following two events to handle the "Loading..." and "Done" states.

    ... data table code ...

        }).on('preXhr.dt', function ( e, settings, data ) {
    
            $(".thealert").html("Loading");
    
        }).on( 'draw.dt', function () {
    
            $(".thealert").html("Done");
    
        }); 
    

    I hope that helps.

    0 讨论(0)
  • 2021-01-21 04:04

    There is way the to display loading message on jQuery DataTable:

    $('#myTableId').DataTable({
            "language": {
                'loadingRecords': 'Processing...',
            },
    
      // 'processing': true,
    .
    .
    })
    

    On above code, // 'processing': true, is commented out, if not there will be two loading messages.

    You also can do this way:

    $('#myTableId').DataTable({
                "language": {
                    'loadingRecords': '&nbsp;',
                    'processing': 'Loading...'
                },
    

    You can also show the loading spinner:

    $('#myTableId').DataTable({
                    "language": {
                        "loadingRecords": "<span class='fa-stack fa-lg'>\n\
                                <i class='fa fa-spinner fa-spin fa-stack-2x fa-fw'></i>\n\
                           </span>&emsp;Processing ..."
                    },
    
    0 讨论(0)
提交回复
热议问题