Skip to content

Commit

Permalink
grid.View: createViewData() => opt out, if the store has no items #6224
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Jan 14, 2025
1 parent 98e9d93 commit 799f258
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
21 changes: 7 additions & 14 deletions src/grid/View.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GridView extends Component {
* @protected
*/
afterSetAvailableRows(value, oldValue) {
if (value > 0 && this.store.getCount() > 0) {
if (value > 0) {
this.createViewData()
}
}
Expand Down Expand Up @@ -228,9 +228,7 @@ class GridView extends Component {
// for changing an array inline, we need to use the leading underscore
me._visibleColumns[1] = value.length - 1;

if (me.store.getCount() > 0) {
me.createViewData()
}
me.createViewData()
}
}

Expand Down Expand Up @@ -498,29 +496,24 @@ class GridView extends Component {
*/
createViewData() {
let me = this,
{bufferRowRange, selectedRows, startIndex} = me,
{bufferRowRange, startIndex, store} = me,
rows = [],
endIndex, i;

if (me.availableRows < 1 || me.columnPositions.length < 1) {
if (store.getCount() < 1 || me.availableRows < 1 || me.columnPositions.length < 1) {
return
}

endIndex = Math.min(me.store.getCount(), me.availableRows + startIndex + bufferRowRange);
endIndex = Math.min(store.getCount(), me.availableRows + startIndex + bufferRowRange);
startIndex = Math.max(0, startIndex - bufferRowRange);

for (i=startIndex; i < endIndex; i++) {
rows.push(me.createRow({record: me.store.items[i], rowIndex: i}))
rows.push(me.createRow({record: store.items[i], rowIndex: i}))
}

me.getVdomRoot().cn = rows;

me.promiseUpdate().then(() => {
if (selectedRows?.length > 0) {
// this logic only works for selection.grid.RowModel
Neo.main.DomAccess.scrollToTableRow({appName: me.appName, id: selectedRows[0]})
}
})
me.update()
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/DomAccess.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const
lengthRE = /^\d+\w+$/,

capturePassive = {
capture : true,
passive : true
capture: true,
passive: true
},

fontSizeProps = [
Expand Down

0 comments on commit 799f258

Please sign in to comment.