[{"id":"b66f8b1e-cc14-4e89-9679-abd5687d283d","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"569bb90a-ea68-46c6-96f1-ab151c120714","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5eb52f08-2d1a-4362-9ffc-4871bdc10f3f","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"341dd607-b97d-4d70-bde2-53acda6b6c95","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"05349273-414f-4208-9ea2-c4fc8f4ea2cb","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"86089f76-b778-4d52-821e-6f27de3df613","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b81e4fd6-1fc5-43a0-a258-b6e16a5cbec6","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8aa8ce31-43e4-438e-951f-241608435260","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"37343f41-6ec2-4c7e-b21d-2cc18d5ce1e0","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5915e52f-64f8-4146-b8bd-81bead6324a3","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"836ba889-af9e-460d-a4cc-c24d922795f2","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4ae14b06-bb68-4394-a210-a46b8f028346","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d8f42066-e9dc-4411-bdcf-43b1a203370c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"7ef86f16-b1a0-49f7-9592-612b9be02b25","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b29c7775-a9a4-451e-a1b5-01d19ed5ca5e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"e56f3989-8f81-46af-90fa-a4813eeb976f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"2526c963-f170-45a8-923e-91b0712a9810","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"24575cf0-501a-44f9-8426-c40f8f4b5552","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1a6f8d7f-acd6-42be-8c4f-f464c6218381","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"82b176fd-5cab-498c-909e-8fa7d29c38d8","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1708b3a9-4f37-44a8-8f0e-f9a2d2e5d940","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"c9ac246e-29fb-4bc4-8231-8439795bb590","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"94f2a5c3-2539-436a-af75-23fbbd1a3957","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d99594f4-2d40-4df4-9419-ba2ca6aa3f7f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"fd66e72d-0f10-4f57-9807-6db26290ab2e","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8f344863-503d-4bc3-a594-3815e7d55f5c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"9be82601-de9d-4c18-948a-23ab6f4dd431","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"6495f3c0-b463-47e0-b08a-ca949672211e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b4bede08-3f08-4839-ba4a-abc7ac195bde","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4afcdfc0-3ff5-4f2b-a223-f8fc042a5bbe","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"422062c4-fa40-4771-a86f-008efe6d86e5","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d87e8013-86a7-4840-8d25-6f62e14eb4ac","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a6acedfd-4043-4c64-a5d1-aec3326df9e7","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"dbdc0b24-06c4-48b9-8d6c-7455119dc773","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a3856849-954a-4cfc-96a6-382e530d3638","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4a39306b-ffa5-433d-80a3-28e41f929b72","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]}]
你可以使用 TableSheet 的撤销和重做功能来逆转和重新应用对数据所做的更改。
本页介绍了支持的操作范围、撤销和重做行为的具体区域以及与数据同步有关的重要注意事项。
TableSheet 的撤销和重做功能支持多种即时操作,包括:
配置更改:筛选、排序等配置设置
运行时 UI 操作:类似于工作表操作,如编辑单元格、添加/删除行或列、粘贴数据、拖动/移动行或列等
TableSheet API:包括除 setDataView
方法外的大多数更改数据或设置的 API 操作。支持的 API 包括 Options
、setDefaultRowHeight
、rowActionOptions
、togglePinnedRows
、togglePinnedColumns
、groupBy
等。API 以与工作表命令相同的方式启用撤销功能。您只需根据需要自定义命令
SpreadJS 设计器支持:撤销和重做功能支持 SpreadJS 设计器中的大多数 TableSheet 操作,如下图所示:
TableSheet 设计功能区:对主要的 TableSheet 功能区选项卡操作执行撤销/重做,如调整行高、堆叠行高、管理状态规则、格式化主题颜色等
TableSheet 列功能区:执行与列配置相关的撤销/重做操作
TableSheet 设计模式:在配置 TableSheet 布局时使用撤销/重做功能
撤销/重做列表:查看和管理您的撤销和重做操作列表。点击列表中的操作项以恢复到选定的操作阶段
下表显示了在不同同步模式下,不同操作的具体撤销行为:
操作 | 静态 | autoSync | 批量 |
---|---|---|---|
添加 | 撤销将删除记录。 | 已保存到服务器:将删除服务器和本地的记录。未保存到服务器:将删除本地记录。 | 撤销将删除记录。本地记录将被删除。 |
更新 | 撤销将还原数据。 | 已保存到服务器:撤销将使其变为脏数据。未保存到服务器:撤销将使状态恢复正常。 | 撤销将还原数据。 |
删除 | 撤销将重新添加记录。 | 状态被添加。 | 撤销将重新添加记录。已保存到服务器:状态被添加。未保存到服务器:状态恢复正常。 |
type=warning
注意事项
数据源标签配置不支持撤销和重做功能。
某些操作会清除撤销堆栈,重置您撤销之前更改的能力。这些操作因运行时环境和设计器模式而异。
运行时:
setDataView
API 将清除撤销堆栈。从服务器重新获取数据将清除撤销堆栈。
tableSheet.reset()
将清除撤销堆栈。设计器:
重置设计器中的表将清除撤销堆栈。
如果表从空状态设置,撤销堆栈不会清除。
重新获取数据将清除撤销堆栈。
每个撤销操作仅修改本地数据,除了在 autoSync 模式下对应于添加行的撤销操作。在此模式下,删除行会直接与服务器同步,撤销此操作会将该行重新添加到列表末尾。
另一种常见方法是使用标志指示删除,允许更灵活的处理。如果希望利用撤销恢复已删除的列,服务器必须支持使用删除标志表示删除。否则,撤销删除行将在前端将其恢复到原始位置。但刷新页面或数据会将该条目移到列表末尾。
以下代码示例展示了添加删除标志的简单例子。运行代码并进行任何更改,然后按 Ctrl + Z 查看撤销操作行为。
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0 });
initSpreadJS(spread);
};
const jsonData = [
{
"Id": 1,
"CompanyName": "Exotic Liquids",
"ContactName": "Grace Campbell",
"ContactTitle": "Purchasing Manager",
"Address": "248 Jac And Mac St",
"City": "Raven",
"Region": "Southeast",
"PostalCode": "24639",
"State": "Virginia",
"Phone": "(276) 964-4382",
"Fax": null,
"HomePage": null
},
{
"Id": 2,
"CompanyName": "New Orleans Delights",
"ContactName": "Bert Garrett",
"ContactTitle": "Order Administrator",
"Address": "5291 Collins Rd",
"City": "Middleburg",
"Region": "Southeast",
"PostalCode": "32068",
"State": "Florida",
"Phone": "(904) 264-9720",
"Fax": null,
"HomePage": null
},
{
"Id": 3,
"CompanyName": "Grandma Kellys Homestead",
"ContactName": "Doris Schultz",
"ContactTitle": "Sales Representative",
"Address": "488 W Loyola Ave",
"City": "Clovis",
"Region": "West",
"PostalCode": "93619",
"State": "California",
"Phone": "(559) 451-0210",
"Fax": null,
"HomePage": null
},
{
"Id": 4,
"CompanyName": "Tokyo Traders",
"ContactName": "Judy Gill",
"ContactTitle": "Marketing Manager",
"Address": "664 N Holden St",
"City": "Port Washington",
"Region": "Midwest",
"PostalCode": "53074",
"State": "Wisconsin",
"Phone": "(262) 284-5862",
"Fax": null,
"HomePage": null
}
]
function initSpreadJS(spread) {
spread.suspendPaint();
spread.clearSheets();
spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
// Initialize a data manager
var dataManager = spread.dataManager();
var myTable = dataManager.addTable("myTable", {
autoSync: true, // Enable the autoSync mode
// This is only for demo. In a real environment, these logics need to be implemented on the server.
remote: {
read: async function () {
return jsonData.filter(item => item._isDelete !== true);
},
delete: async function (item) {
const sourceIndex = deleteItem(item[0]);
return jsonData[sourceIndex]
},
create: async function (changes) {
return createItem(changes);
}
}
});
function deleteItem(dataItem) {
const sourceIndex = jsonData.findIndex(item => item.Id === dataItem.Id);
jsonData[sourceIndex]._isDelete = true;
return sourceIndex;
}
function createItem(dataItem) {
const index = jsonData.findIndex(item => item.Id === dataItem.Id);
if (index > -1 && jsonData[index]) {
jsonData[index]._isDelete = false;
return jsonData[index];
} else {
jsonData.push({ ...dataItem, Id: createID() });
return jsonData[jsonData.length - 1];
}
}
function createID() {
return `${Math.random() * 1000}`;
}
// Initialize a tablesheet
const sheet = spread.addSheetTab(0, 'tablesheet', GC.Spread.Sheets.SheetType.tableSheet);
var rowActions = GC.Spread.Sheets.TableSheet.BuiltInRowActions;
var options = sheet.rowActionOptions();
options.push(
rowActions.removeRow,
rowActions.saveRow,
rowActions.resetRow,
);
sheet.rowActionOptions(options);
// Bind a view to the tablesheet
myTable.fetch().then(function () {
const view = myTable.addView("myView", [
{ value: "Id", width: 50, caption: "Id" },
{ value: "CompanyName", width: 100, caption: "CompanyName" },
{ value: "ContactTitle", width: 100, caption: "ContactTitle" },
{ value: "Phone", width: 100, caption: "Phone" },
{ value: "State", width: 100, caption: "State" }
]);
sheet.setDataView(view);
});
spread.resumePaint();
}