HTML Elements › Forums › General Discussions › How to prepend to DataSource?
Tagged: grid web component
This topic contains 5 replies, has 2 voices, and was last updated by Anonymous 1 year, 6 months ago.
- AuthorPosts
- September 2, 2019 at 6:40 pm #100275
AnonymousI have a data adapter for Grid.
I can add to end with e.g.:
document.addCourseGrid.dataSource.add({id:’mytest’, code:’f123aacdee’});
I can insert somewhere in the rows e.g.
document.addCourseGrid.dataSource.insert(1, {id:'mytest', code:'f123aacdee'});
This will insert in the second position.
But I cannot insert at the top:
document.addCourseGrid.dataSource.insert(0, {id:'mytest', code:'f123aacdee'});
`
smart.grid.row.js:282 Uncaught TypeError: Cannot set property ‘row’ of undefined
at Row.render (smart.grid.row.js:282)
at HTMLElement._renderFrozenRows (smart.grid.core.js:6944)
at HTMLElement._recycle (smart.grid.core.js:6914)
at DataAdapter.notifyFn (smart.grid.core.js:4535)
at DataAdapter._notify (smart.data.js:193)
at DataAdapter.insert (smart.data.js:634)
at <anonymous>:1:35`
- This topic was modified 1 year, 6 months ago by
.
September 2, 2019 at 6:42 pm #100276
AnonymousUgh, sorry about that. The impossible forum software again.
smart.grid.row.js:282 Uncaught TypeError: Cannot set property 'row' of undefined at Row.render (smart.grid.row.js:282) at HTMLElement._renderFrozenRows (smart.grid.core.js:6944) at HTMLElement._recycle (smart.grid.core.js:6914) at DataAdapter.notifyFn (smart.grid.core.js:4535) at DataAdapter._notify (smart.data.js:193) at DataAdapter.insert (smart.data.js:634) at <anonymous>:1:35
- This reply was modified 1 year, 6 months ago by
.
September 2, 2019 at 6:47 pm #100279
AnonymousSorry, I can’t find how to delete a post, I have to leave the duplicate above.
I looked at source code, and I find nothing that seems to prepend. Only add() and insert().
September 2, 2019 at 6:59 pm #100281Based on: https://www.htmlelements.com/demos/grid/dynamic-rows/.
Use rows.splice(0, 0, createRow()); in the example, within the addRow click handler.
Regards,
GeorgeSmart Html Elements Team
https://www.htmlelements.com/September 2, 2019 at 7:09 pm #100282
AnonymousI would prefer to work with the bound data, though.
I’m afraid I am thoroughly confused about adding rows by creating a row and adding nodes to the grid, vs. adding rows to the data source.
The latter is my preference, and it does work, but only for append and insert but not insert at top.
I had hoped I could manipulate the data source, as it is most convenient for e.g. update an array from a REST fetch, but only having partial luck with this. Works if I want to add to the end or middle, just not at the top.
September 2, 2019 at 7:18 pm #100284
AnonymousThe problem was that I had the first row frozen. It will get an exception as shown above if you try to insert before a frozen row.
If not frozen, then I can insert at 0, and it works. This gives me the most-recent-first insertion I want to show history.
I can see that it’s not obvious what the “correct” behaviour might be. It depends on the full definition of what you consider to be “frozen”.
I think anyway I didn’t need to freeze, as I just want to freeze the headers. I supposed the headers are automatically frozen anyway.
- This topic was modified 1 year, 6 months ago by
- AuthorPosts
You must be logged in to reply to this topic.