英文:
Is there a better way to scroll focused cell in a table?
问题
我目前正在修改逻辑以查找并聚焦于表格中所需的行。
在某些情况下,上面的代码无法正确滚动到所需的行。这可能是因为setFocusedCell()函数不能保证在表格部件完全渲染之后执行。一个可能的解决方案是在表格完成渲染后使用出现事件("appear")来处理焦点逻辑。
然而,上述逻辑仅在表格新创建时有效。
我计划修改代码,以确保setFocusedCell()函数在部件完全渲染后执行,使用异步的sleep()函数。您是否有其他更好的方法建议?
如果有关于qooxdoo的任何不正确的理解或有用的信息,请告诉我。谢谢。
英文:
I am currently working on modifying the logic to find and focus on the desired row in a table.
https://qooxdoo.org/qxl.apiviewer/#qx.ui.table.Table~setFocusedCell!method_public
var table = new qx.ui.table.Table(tableModel);
// some logics for finding matched row
table.setFocusedCell(col_Idx, row_idx, true);
In certain cases, the code above does not properly scroll to the desired row.
This is likely because the setFocusedCell() function is not guaranteed to execute after the table widget has been fully rendered.
One possible solution is to handle the focus logic after the table has finished rendering using the appear event.
var table = new qx.ui.table.Table(tableModel);
table.addListenerOnce("appear", () => {
// some logics for finding matched row
table.setFocusedCell(col_Idx, row_idx, true);
});
However, the above logic only works when the table is newly created.
I am planning to modify the code to ensure that the setFocusedCell() function is executed after the widget has been fully rendered, using async sleep().
Do you have any other suggestions for a better approach?
And if there is any incorrect understanding or helpful information related to qooxdoo,
please let me know. Thank you.
答案1
得分: 1
你可以使用事件appear
和Promise概念的混合方式。如果事件被触发一次,那么Promise将被解析,在代码的任何地方,你可以附加then
方法到Promise并执行你的特定代码。将这种方法视为高级标志。
const col_Idx = 1;
const row_idx = 1;
const promise = new Promise(function(resolve, reject){
table.addListenerOnce("appear", () => {
resolve();
});
}, this);
promise.then(function(){
table.setFocusedCell(col_Idx, row_idx, true);
});
英文:
You could use some mix of event appear
and promise concept.
If the event is emitted one time then promise will be resolved and in any place of code you could attach method then
to the promise and execute your specific code.
Consider this approach as advanced flag.
const col_Idx = 1;
const row_idx = 1;
const promise = new Promise(function(resolve, reject){
table.addListenerOnce("appear", () => {
resolve();
});
}, this);
promise.then(function(){
table.setFocusedCell(col_Idx, row_idx, true);
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论