JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Data Grid › Dynamic resize of a row due to complex cell editor
- This topic has 12 replies, 4 voices, and was last updated 9 months, 3 weeks ago by Catdoken.
-
AuthorPosts
-
January 27, 2024 at 4:12 am #109752CatdokenParticipant
I have a few questions. I created a complex cell editor that has a spinner, a textfield, and the ability to add new HTMLElement objects (a div with a span) based on user input of the spinner/textfield. In doing so the cell needs to be resized and therefore the entire row as new divs are added.
It makes sense the Grid will have to re-render the row if I change the height property, but in doing so it kicks me out of editing that cell. I was not surprised about this but want to check if its possible to remain in edit mode. I have some ideas on how to possibly do this, but none of it is elegant.
For reference I am using the onRender, getValue, onInit methods of generating a cell editor.
As an alternative it is possible to show a pop-up via double clicking a cell? Maybe Smart.Window? I’ve seen examples out there, but it did not look specific to what I am trying to do (https://www.htmlelements.com/angular/demos/grid/nested-grids-dialog/).
Thanks!
- This topic was modified 10 months, 1 week ago by Catdoken.
January 28, 2024 at 7:00 pm #109758adminKeymasterHi Catdoken,
You can use the rowClick event which occurs when a row is clicked and open a Smart.Window for custom editing purposes. As for the resize, you are right, when a row is resized, it needs to be re-rendered. With methods such as beginCellEdit and beginRowEdit, you can restart the editing process, too.
Regards,
PeterSmart UI Team
https://www.htmlelements.com/February 2, 2024 at 11:41 pm #109787CatdokenParticipantThanks, I found a path forward on this. Using beginCellEdit was what I needed.
A few other questions:
- Is there a way to know when a row is resized by the UI, not by a human. There is the onRowResize listener, but it does not get called as that must be when one manually changes height via dragging the edges. I don’t think this is built into the architecture but figured I’d ask. The use case is to know when a row has to repaint itself so I can reopen the edit cell. I am trying to keep everything single click. If I am editing a row and I click another row, that previous row should end its edit and the newly clicked cell enter edit mode. If there is a height difference between the template and the editor the row will repaint killing the edit of the clicked cell.
- Any pointers on changing the CSS of a smart component inside a grid cell, specifically the template? For example a smart-input inside a smart-grid cell. I think using the smart-input has made life harder since it is using its own CSS where if I just used a <div>{{value}}</div> raw HTML the grid CSS would take over. I did not opt to use the built in templates via the strings like ‘input’, ‘date’, etc. I wanted to roll my own. I can change some things (see below), but color does not work at all. It is hard to follow sometimes given there are hundreds of CSS properties some of which are shared across many components.
if (!data.template) {
const input = document.createElement(‘smart-input’);input.style.border = ‘none’;
input.style.marginLeft = ‘0.50px’;
input.style.width = ‘100%’;
// cant change background colorinput.value = data.value;
data.template = input;
} else {
….
}February 5, 2024 at 2:25 pm #109802MarkovKeymasterHi,
1. The rowResize event is called only when the row size is updated by the user via drag and resize of a row header. It is not called when you manually set row height by using the row’s height property.
2. The .smart-grid-cell-editor CSS class is applied to cell editors and you can use it for styling purposes.
Regards,
MarkovSmart UI Team
https://www.htmlelements.com/February 5, 2024 at 3:32 pm #109803CatdokenParticipantThat is what I figured with the resize. No problem, I worked around it and have all cells opening via single click.
I’ll take a look at the CSS class. I am planning to change the styles problematically. In doing so it looks like I need to grab an instance of the HTMLElement that has a class of ‘smart-input’ in order to change the color.
Thanks.
February 6, 2024 at 11:20 pm #109805CatdokenParticipantI have another question regarding row resizing.
I have the grid in an Angular application so it is created when the component it lives in is created. When I first bring up the component the row resizing works correctly. I set the height on the row via row.height = xxxx. I also tried grid.setRowProperty.
If I close the component then re-open it resizing on longer works. I can set row.height to anything, nothing sticks. Maybe there is some old data or references that were not cleaned up. I assume there is an ngOnDestroy method for any angular representation of a SmartHTML component. Is there anything I am not doing that I need to when destroying the table?
I have not set any properties on grid.layout (no auto height). My guess is it is getting re-created and kills any changes. The template/editors are re-drawn throughout the grids life. I was under the impression if I changed the rowHeight to xxx it would stick, but I must be misunderstanding nuances of how the properties are persisted.
Overall is dynamically changing the height of a row something that is supported? I am sure it is technically in that it is possible, but is it something that is considered “normal” for the Grid? I am asking in terms of just setting row.height several times after the grid has been initialized. I know there is layout.rowHeight, onRowInit, behavior of growAndShrink which I believe is you manually use the mouse to change the height.
My use case is I have a cell editor that is complex, needs more height. I don’t want to set the row height to a fixed value that is good for the editor because the template/renderer does not need to be that high. I’d like the row to use as little height as possible.
February 7, 2024 at 8:58 am #109807MarkovKeymasterHi Catdoken,
I would request a stackblitz sample in order to test the specific use case.
Regards,
MarkovSmart UI Team
https://www.htmlelements.com/February 7, 2024 at 2:47 pm #109808CatdokenParticipantI tracked this down to the isDirty boolean found on grid.layout. The first time it is false and everything works as expected. If I close the component that has the grid and then re-open isDirty is true. I’ll look in the source to see if I can learn more, but short story is setting isDirty to false in ngAfterViewInit (using bracket notation) works great, no more issues.
This is a workaround I’ll be using for now, but I am not 100% sold on it since isDirty is not something that is exposed in the API (using typescript here) so I interpret that as a property that is not meant to be changed manually.
I can try to create a stackblitz example, if so I’ll post here.
February 8, 2024 at 3:38 pm #109815MarkovKeymasterHi Catdoken,
I suppose the Grid is removed from the DOM and re-attached to it in your use-case and that may be the reason of internal set of this flag and re-calc of the row height. We will try to reproduce this scenario locally and update the component’s behavior.
Regards,
MarkovSmart UI Team
https://www.htmlelements.com/February 13, 2024 at 12:25 am #109820CatdokenParticipantOk, sounds good. With my setup the grid should be removed from the DOM when I close the entire UI then bring it back up. The part that handles the display of the grid is backed by an Angular ngIf.
I do have a new question – is there a way to bulk edit multiple cells without having the grid redraw per cell? Maybe its in the API and I missed it. I am looking for something similar to GridCell.setProperties which lets you change multiple properties that then trigger a redraw. I am looking to do the same, but edit multiple properties across multiple cells. If I use GridCell.setProperties for each cell it looks like the grid is kicking off a redraw per cell – makes sense.
February 13, 2024 at 1:45 am #109821CatdokenParticipantI do see beginUpdate and endUpdate – does that work in conjunction with cell.setProperties preventing a refresh?
February 14, 2024 at 7:33 pm #109826ivanpeevskiParticipantHi Catdoken,
Yes, beginUpdate and endUpdate also work with setProperties. To use them, you should call them in this order:
grid.beginUpdate();
//make updates
grid.endUpdate();
Best Regards,
Ivan PeevskiSmart UI Team
https://www.htmlelements.com/February 16, 2024 at 10:51 pm #109839CatdokenParticipantAny tips on the scroll bar. When I add enough rows that a scrollbar appears I get two issues:
- The vertical scrollbar consumes part of the last cell. Seems to me the width of the table must be fixed and the scrollbar is forced to eat part of the last cell so it will fit. I am overriding the width via –smart-grid-default-width: 100%;, otherwise the grid seems to ignore the cell widths I set. Might just be how I have the HTML/CSS set on my end.
- More importantly when I scroll up/down the grid seems to be having trouble moving to other rows. If I populate data for the first row, scrolling down always has me still seeing the first row at the top.
- I opted to keep the scrolling at the default “physical”.
- I opted to not make a custom dataSource as the tree will go ahead and make its own.
- I use grid.addRow(…) to add an object that looks like this:
- {
‘Option 1’: <value>,
‘Option 2’: <value>,
etc….
};
- {
- I use grid.addRow(…) to add an object that looks like this:
What might I be missing? Is having the tree create the data source not the way to go? Perhaps the custom cell templates are the problem.
Edit: I may see the problem now, it is the templates. Leaving the post here if you have any pointers. Performance seems slower then usual, but I suspect its the re-drawing of the cells. Redrawing seems to get called excessively. I can perhaps add logic to not do heavy lifting unless something actually changed. If I changed one cell of row 1 it seems to kick off a repaint of all cells in all rows.
-
AuthorPosts
- You must be logged in to reply to this topic.