我正在将一个Excel工作表导入到HTML表中。我想要本教程中的列切换按钮,以便用户可以选择/取消选择列- https://www.w3schools.com/jquerymobile/tryit.asp?filename=tryjqmob_tables_columntoggle
如何如示例中所示附加数据优先级并自动递增?
function BindTable(jsondata, tableid) {/*Function used to convert the JSON array to Html Table*/
var columns = BindTableHeader(jsondata, tableid); /*Gets all the column headings of Excel*/
for (var i = 0; i < jsondata.length-1; i++) {
var row$ = $('<tr/>');
for (var colIndex = 0; colIndex < columns.length; colIndex++) {
var cellValue = jsondata[i][columns[colIndex]];
if (cellValue == null)
cellValue = " ";
row$.append($('<td/>').html(cellValue));
}
$(tableid).append(row$);
}
}
function BindTableHeader(jsondata, tableid) {/*Function used to get all column names from JSON and bind the html table header*/
var columnSet = [];
var headerTr$ = $('<tr class="header"/>');
for (var i = 0; i < jsondata.length; i++) {
var rowHash = jsondata[i];
for (var key in rowHash) {
if (rowHash.hasOwnProperty(key)) {
if ($.inArray(key, columnSet) == -1) {/*Adding each unique column names to a variable array*/
columnSet.push(key);
headerTr$.append($('<th onclick="sort()" title="Click to Sort" < />').html(key));
}
}
}
}
$(tableid).append(headerTr$);
return columnSet;
}