Когда я разрабатываю таблицу и добавляю ее в элемент div, я не вижу функции сортировки в каждом столбце.
Это работает, когда я создаю простую HTML-таблицу с жестким кодом с атрибутами таблицы Bootstrap, такими как функция сортировки (data-sortable="true"). Я считаю, что когда страница загружается, загрузочный файл обнаруживает атрибуты и его атрибуты, находящиеся в теле html. Но когда я динамически создаю таблицу начальной загрузки, таблица HTML присутствует, но нет функции таблицы начальной загрузки.
Пожалуйста, помогите. Вот мой код ниже того, как я разрабатываю таблицу, используя функцию javascript.
Код: Выделить всё
// result is a large string of result when ajax is sending a response.
function displayResult(result) {
//convert the result into Array of JSON
var splitResult = result.split("*split*");
var getLast = splitResult.length - 1;
for(var i = 0; i < splitResult.length; i++){
if(i != getLast) {
splitResult[i] = JSON.parse(splitResult[i]);
} else {
splitResult.splice(i,1);
}
}
// the .pagination is a function that is use in pagination.js
// the #page is a DIV
$('#page').pagination({
dataSource: splitResult,
pageSize: 8,
callback: function(data, pagination) {
// template method
var html = template(data);
// grab the html String and append it into the #demo DIV
$("#demo").append(html);
}
})
}
function template(data) {
// table tag with bootstrap-table attributes
var html = '';
// create the table headers
html = html + 'IDZIP 11Date'
+ '';
// input the results of the data
if (data[0].IDCODE) {
$.each(data, function(index, item) {
html += ''
+ item.IDCODE+''
+ '' + item.ZIP11_ID + ''
+ '' + item.DEL01_TS + '';
});
} else {
$.each(data, function(index, item) {
html += ''+ item +'';
});
}
html += '';
return html;
}
Подробнее здесь: https://stackoverflow.com/questions/553 ... ynamically
Мобильная версия