0

We want to show ADD User button or link in place of "No matching records found" message if we get 0 records. Also we need pass searched id with the link

How we can implement this.

Ex:

------------------------------------------------
                    ADD User link
------------------------------------------------

I was trying with :

"fnDrawCallback": function(retObj) {
        if(userTable.rows().data().length==0){

        }
 },

Edited:

 var userTable=$('#allUsers').DataTable({
    "processing": true,
    "serverSide": true,
    'responsive': true,"stripeClasses": [ 'odd-row', 'even-row' ],
    "aoColumnDefs": [
      { 'bSortable': false, 'aTargets': [1,2,3,4,5] }
    ],
    "ajax": {
                url: "users_list.php",
                type: 'GET',
                data: userData
    },
    "fnDrawCallback": function(retObj) {
        if(userTable.rows().data().length==0){
            console.log("0 records");
        }
    },
    "language": {
        "infoFiltered": "",
        search: "_INPUT_",
        searchPlaceholder: "Search...",
        "emptyTable": '<a href="/path/' + 1 + '">BOOK THIS COURSE</a>'
    },
    "pageLength": 10
    });

still getting "No matching records found" message.

1 Answer 1

2

Use language.emptyTable option to define a message when there are no records in the table.

For example:

var table = $('#example').DataTable({
   'language': {
      'emptyTable': '<a href="/path/' + 1 + '">Add new user</a>'
   }
});

See this example for code and demonstration.

Use can also use language.zeroRecords option to define a message when the table is empty due to filtering.

Sign up to request clarification or add additional context in comments.

3 Comments

Added code. Please refer edited code in question. But still I'm getting "No record found" message.
I have added "zeroRecords" instead of "emptytable". Now it is working. Thanks for your reply
@stefun, I didn't realize you wanted the message to be shown when table is empty due to filtering, added more details to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.