【发布时间】:2015-08-22 21:40:09
【问题描述】:
我是 Handsontable 的新手,在我的应用程序中单击按钮(表格编辑器),我打开了(TableEditor.html)最初有 10 行和 10 列的handsontable,用户可能会使用一些行和列剩下的都是空的,使用我的代码它也给出了空单元格:(,我想在点击按钮“加载”之后和在json中加载它之前从handsontable中删除空行和列? 我的代码如下:
TableEditor.html
<html>
<head>
<script src="http://handsontable.com/dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="http://handsontable.com/dist/handsontable.full.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<div id="hot"></div>
<input type="button" name="load" id="load" value="Load">
<script>
var data = [[]];
var container = document.getElementById('hot');
var hot = new Handsontable(container,
{
data: data,
rowHeaders: true,
colHeaders: true,
minSpareRows: 0,
colHeaders: true,
contextMenu: true,
minRows: 10,
minCols:10,
mergeCells: true,
contextMenu: true,
removeRowPlugin: true
});
Handsontable.Dom.addEvent(load, 'click', function() {
for(var i=0; i<hot.countRows();i++)
{
//alert('Done...'+hot.isEmptyRow(i)+'-- '+i);
if(hot.isEmptyRow(i))
{
hot.alter('remove_row', i);
//alert('Removed...'+i);
}
}
for(var j=0; j<=hot.countCols();j++)
{
alert('Done...'+hot.isEmptyCol(j)+'-- '+j);
if(hot.isEmptyCol(j))
{
hot.alter('remove_col', j) ;
alert('Removed...'+j);
}
}
$.ajax('json/save.json', 'GET', JSON.stringify({"data": hot.getData()}), function (res) {
alert('Done...');
var response = JSON.parse(res.response);
alert('Done...');
if (response.result === 'ok') {
alert('Data saved');
}
else {
alert('Save error');
}
});
});
</script>
</body>
</html>
它提供如下数据:
b,c,,,,,,,,,c,b,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,
【问题讨论】:
标签: javascript jquery