В этом случае вы можете использовать Табулятор. вы можете загрузить данные json внутрь, и это дает вам множество функций и возможность стилизовать таблицу.
здесь вы можете прочитать о том, как вставить данные из ajax запроса: http://tabulator.info/docs/4.1/data#ajax
, если вы хотите сделать запрос и ввести ответ в таблицу, вы можете сделать это после того, как получите ответ от вашего кода:
var table = new Tabulator("#example-table", {
height: '70%', // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
data: res.json, //assign data to table, json response
layout: "fitDataFill", //fit columns to width of data
pagination: "local",
paginationSize: 10,
paginationSizeSelector: [5, 10, 15, 20],
movableColumns: true,
selectable: true,
columns: [
{
formatter: "buttonCross", align: "center", title: "del", headerSort: false, cellClick: function (e, cell) {
if (confirm('Are you sure you want to delete this entry?'))
cell.getRow().delete();
console.log(rowJson = cell.getRow().getData())
}
},
{ title: "id", field: "id", sorter: "number" },
{ title: "Name", field: "name", sorter: 'string' },
{ title: "phone", field: "phone", sorter: "number" },
{ title: "email", field: "email", sorter: 'string' },
{ title: "location", field: "location", sorter: 'string' },
{ title: "price/night", field: "price", sorter: 'number' },
{ title: "number of rooms", field: "roomsnumber", sorter: 'number' },
{ title: "capacity", field: "capacity", sorter: 'number' },
{ title: "available", field: "available", sorter: 'string' },
{ title: "start time", field: "startTime", sorter: 'string' },
{ title: "date", field: "date", sorter: "date", },
]
});
это очень просто в использовании и есть много функций ..