From 37ce689cd8045f081114a3cbf22157fc6f5f36f1 Mon Sep 17 00:00:00 2001 From: Masha_Rudenko Date: Tue, 12 May 2026 13:31:02 +0300 Subject: [PATCH 1/2] [add] a guide for the awaitRedraw helper --- docs/awaitredraw.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ sidebars.js | 3 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 docs/awaitredraw.md diff --git a/docs/awaitredraw.md b/docs/awaitredraw.md new file mode 100644 index 00000000..0133dfcb --- /dev/null +++ b/docs/awaitredraw.md @@ -0,0 +1,45 @@ +--- +sidebar_label: AwaitRedraw helper +title: AwaitRedraw helper +description: You can explore the AwaitRedraw helper in the documentation of the DHTMLX JavaScript Spreadsheet library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Spreadsheet. +--- + +# AwaitRedraw helper + +Some API methods of DHTMLX Spreadsheet take effect only after the component is rendered on the page. In some cases this can take a moment, so you need to wait until the browser completes rendering before running the next piece of code. + +For such cases, you can use the **dhx.awaitRedraw** helper. It tracks the rendering cycle and runs your code as soon as Spreadsheet completes its rendering. + +~~~js +dhx.awaitRedraw().then(() => { + // your code here +}); +~~~ + +## Usage examples + +### Read a cell value after data loads + +Use `awaitRedraw` to make sure the cell value is available before reading it: + +~~~js +spreadsheet.events.on("afterDataLoaded", () => { + dhx.awaitRedraw().then(() => { + const value = spreadsheet.getValue("A1"); + console.log(value); + }); +}); +~~~ + +### Set focus after a sheet switch + +Calling `setFocusedCell` right after a sheet switch has no visible effect because the new sheet hasn't finished rendering yet. Use `awaitRedraw` to set focus once it has: + +~~~js +spreadsheet.events.on("afterSheetChange", (sheet) => { + dhx.awaitRedraw().then(() => { + console.log(sheet.name); + spreadsheet.selection.setFocusedCell("A1"); + }); +}); +~~~ diff --git a/sidebars.js b/sidebars.js index e20c266e..3ec7a0db 100644 --- a/sidebars.js +++ b/sidebars.js @@ -273,7 +273,8 @@ module.exports = { "themes/custom_theme" ] }, - "using_typescript" + "using_typescript", + "awaitredraw" ] }, { From ee1cbbac42d815ed002636584861a9550cee7276 Mon Sep 17 00:00:00 2001 From: Masha_Rudenko Date: Wed, 13 May 2026 16:30:53 +0300 Subject: [PATCH 2/2] [update] simplify awaitRedraw guide - removed the Usage examples section heading in favor of a lead-in sentence - removed the sheet switch example (works without awaitRedraw) --- docs/awaitredraw.md | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/docs/awaitredraw.md b/docs/awaitredraw.md index 0133dfcb..e51c9452 100644 --- a/docs/awaitredraw.md +++ b/docs/awaitredraw.md @@ -16,11 +16,7 @@ dhx.awaitRedraw().then(() => { }); ~~~ -## Usage examples - -### Read a cell value after data loads - -Use `awaitRedraw` to make sure the cell value is available before reading it: +For example, use `awaitRedraw` inside `afterDataLoaded` to make sure the cell value is available before reading it: ~~~js spreadsheet.events.on("afterDataLoaded", () => { @@ -31,15 +27,3 @@ spreadsheet.events.on("afterDataLoaded", () => { }); ~~~ -### Set focus after a sheet switch - -Calling `setFocusedCell` right after a sheet switch has no visible effect because the new sheet hasn't finished rendering yet. Use `awaitRedraw` to set focus once it has: - -~~~js -spreadsheet.events.on("afterSheetChange", (sheet) => { - dhx.awaitRedraw().then(() => { - console.log(sheet.name); - spreadsheet.selection.setFocusedCell("A1"); - }); -}); -~~~