简体   繁体   中英

How to add pagination to table created usign javascript?

I am creating a table from javascript and I want to add a pagination to this table. Is there any way to do this?

output += '<table class="table">';

//Some other code

info.fields.forEach(function (field) {    
      if (infoData.hasOwnProperty(field.key)) {
             var data = infoData[field.key];
             data = (data == null) ? "-" : data;
             output += '<td>' + data + '</td>';  
      } else {
             output += '<td>-</td';
      }
});

You can use a light weighted javascript library datatable .

EDIT

Yes, there are many library which can help you but I personally use datatable.

HOW TO USE:

Add library's css and js .

When creating table add id to the table <table id="tableId"> after that initialize the datatable like below.

$('#tableId').DataTable();

NOTE: don't forget to add css and js file and first create table then initialize .DataTable().

For more datatable options click here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM