我是新手。我使用EJ电子表格表显示电子表格JS。我想将"一个电子表格中的所有表"与另一个比较。谁能使用普通JavaScript
可以通过比较从表格对象检索的遇到的" dataSource"属性来实现您的要求。在这里,数据将使用DataSource属性串到电子表格,并在按钮点击事件中比较了两个电子表格的数据源。
您可以在下面的工作代码中尝试使用,也可以参考示例http://jsplayground.syncfusion.com/2pd3dmtq
<button id ="btn" onclick="onClick()">Click To Compare</button>
<h2> Spreadsheet1</h2>
<div id="Spreadsheet1"></div>
<h2>Spreadsheet2</h2>
<div id="Spreadsheet2"></div>
<script>
datasource = [
{ OrderID: 10001, CustomerID: "VINET", Freight: 12.256, Load: 123456 },
{ OrderID: 10002, CustomerID: "TOMSP", Freight: 23.3, Load: 1234 },
{ OrderID: 10003, CustomerID: "HANAR", Freight: 12.256, Load: 123456 },
{ OrderID: 10004, CustomerID: "VICTE", Freight: 23.3, Load: 1234 },
{ OrderID: 10005, CustomerID: "SUPRD", Freight: 12.256, Load: 123456 },
{ OrderID: 10006, CustomerID: "CHOPS", Freight: 23.3, Load: 1234 },
];
datasource1 = [
{ OrderID: 10001, CustomerID: "VINET", Freight: 12.256, Load: 123456 },
{ OrderID: 10002, CustomerID: "TOMSP", Freight: 23.3, Load: 1234 },
{ OrderID: 10003, CustomerID: "HANAR", Freight: 12.256, Load: 123456 },
{ OrderID: 10004, CustomerID: "VICTE", Freight: 23.3, Load: 1234 },
{ OrderID: 10005, CustomerID: "SUPRD", Freight: 12.256, Load: 123456 },
{ OrderID: 10006, CustomerID: "CHOPS", Freight: 23.3, Load: 1234 }]
$(function () {
$("#Spreadsheet1").ejSpreadsheet({
showRibbon: false,
allowFormulaBar: false,
columnWidth: 100,
sheets: [{
dataSource: window.datasource // Bind data for sheets using dataSource property
}
],
});
$("#Spreadsheet2").ejSpreadsheet({
showRibbon: false,
columnWidth: 100,
allowFormulaBar: false,
sheets: [{
dataSource: window.datasource1 // Bind data for sheets using dataSource property
}],
});
});
function onClick(args) {
var ssObj1 = $("#Spreadsheet1").data("ejSpreadsheet"), ssObj2 = $("#Spreadsheet2").data("ejSpreadsheet"),
sheet1ActIdx = ssObj1.getActiveSheetIndex(),sheet2ActIdx = ssObj2.getActiveSheetIndex(),
sheet1DataSrc = ssObj1.getSheet(sheet1ActIdx).dataSource, // To access the datasource by passing the sheetIndex
sheet2DataSrc = ssObj2.getSheet(sheet2ActIdx).dataSource;
alert("The Datasource for Spreadsheet1 and Spreadsheet2 are " + (JSON.stringify(sheet1DataSrc) == JSON.stringify(sheet2DataSrc) ? "same": "different"));
}
</script>
您可以检查样本,让我们知道它是否满足您的要求。
对不起问题。我尝试像ssobj1.saveasjson()一样转换为json;但是dataconatiner [shareddata]和rowcount colcount表中的整个表格值在模型上。