We are currently using this prop in ag-grid.
onDisplayedColumnsChanged={event => event.api.sizeColumnsToFit()}
It is helpful for preventing whitespace from showing up when we hide a column, as well as keeps horizontal scrolling to a minimum when we unhide a column. We also use it for similar reasons when grouping on a particular column(s).
Unfortunately, it prevents us from using other features of Ag-Grid, such as selecting the option to resize a column to fit its contents. It also prevents columns that have been manually resized from keeping their size when they are moved somewhere else on the grid.
Is there any way to check for whether a column is being added/removed/grouped? the event object provided by the onDisplayedColumnsChanged prop only exposes the columnApi, api, and type properties. I haven't found anything useful in those so far.
I've considered creating a useEffect that will sizeColumnsToFit when the gridApi changes, but I believe I hit the same issue there with not having any useful properties to trigger the effect.
You can tell AG Grid columns to ignore sizeColumnsToFit() by setting the property suppressSizeToFit to true:
https://www.ag-grid.com/javascript-data-grid/column-sizing/#size-columns-to-fit
You can set the property on-the-fly by listening to one of the column events where auto-sizing should be disabled:
https://www.ag-grid.com/javascript-data-grid/grid-events/#reference-columns
Related
I am trying to display a grid with nested rows. My data has a children property with objects similar or almost exactly as the parent one.
I have tried giving some of my columns a cellRenderer property of 'group'.
I have been using getNodeChildDetails, but it seems like this method got deprecated and the new way of doing this is to specify a property on every row called path, which I find to be a pretty weird and ugly approach.
getNodeChildDetails mentioned above does not support any changes inside the row, therefore it is not of good use for me.
is there a method replacement for getNodeChildDetails that would have the same functionality?
All I want to do is group by row some data on whether it has a children property or not.
I am making WPF application.I have a data grid and all columns have set their width to "Auto".When i start scrolling through the table some of the columns start expanding.My question is: Can I set the column width to fit the longest data in column at the beginning (without expanding columns when i scroll)?
the column width for wpf expanding when the shown data need more space when it set to Auto then this work will be done automatically.
Well this is due to the virtualization of the DataGrid. Only the items, which are visible are rendered and the controls are reused in case of scrolling (if you are activating it). And so the width will not be correct, since the longest element is not rendered yet. A list control performs very well, although you might bind many items to it.
I think you have 2 options
Turning off the virtualization, which might be a proper solution, if you don't have many items to show. I've to admit, I didn't try it, so no warranty. You can turn it off via <DataGrid VirtualizingStackPanel.IsVirtualizing="False"/>. For more information on the VirtualizationStackPanel pls have a look here.
Another solution may be TextTrimming. TextBlocks can show Ellipses if the text is too long. Therefor you will have to assign a custom datatemplate to the column put the following as content e.g. <TextBlock Text="{Binding}" TextTrimming="WordEllipsis"/>. Please note, that you will also have to provide a customer CellEditingTemplate, if the user shall be able to edit the values. For more information about TextTrimming please have a look here. To get an idea how the whole DataTemplate thing regarding DataGrids will work, you can have a look here.
I'm considering a UI design (using WPF), but I'm not sure how to implement a critical feature: The user will be assigning needs to resources. There are some rules about what assignments can be made, such as compatibility and availability. I would like to display a list of resources, and a list of needs. The user can make an assignment by dragging a need and dropping it onto an resource.
What I would like to do is show the user what possible assignments can be made by highlighting all assignable resources for a given need. This should be done when dragging any given need.
(I'm comfortable performing the highlight using a property on the resource ViewModels and triggers in XAML, and performing the drag & drop action.)
I don't see any events that are generic to dragging starting or stopping; they are either relevant to the source element, or to elements that are actively being dragged over. How can I evaluate a method to evaluate compatibility on every resource item when a drag is started?
EDIT:
As I am thinking about this more, it might be better to perform the highlighting function upon selection of the item rather than the start of dragging. As the items will typically be in ListViews or TreeViews, dragging will also cause the item to become selected. Additionally, the user will not have to initiate and hold a drag while considering their choices. As the list of targets may be long, the user may need to scroll to find one they want, which is not practical while dragging.
I can easily listen for the SelectionChanged events to evaluate the potential drop targets.
In WPF the drag drop services are well defined along with indicating applicability of which are valid draggable and droppable visuals for the dragged data.
http://msdn.microsoft.com/en-us/library/ms742859.aspx
EDIT
As per your requirement you need to indicate \ highlight \ focus valid droppable targets when drag starts.
For this the droppable visuals must register themselves for the type of data that is getting dragged. All drop targets will thus be notified when such data that they have registered for is getting dragged i.e. in DragDrop.DoDragDrop(..., <dragged data>, ...) call.
Now this is tricky, but you could use Clipboard services to hold the dragged data. The registered target visuals will be notified by the same Clipboard service when such data is added to the clipboard. You could have a command CanExecute() that constantly executes on the drag - drop view and checks the clipboard data is of the registered data type. If so it will set some view model based boolean property that has been attached against all those valid drop targets to true, that will highlight them thru the attached behavior.
In the case of falling back (drag or drop lost), the clipboard must be cleared.
But ofcourse this is easy said than done.... but worth a try.
While I have updated the question with my plans to pursue another UI approach (highlight upon selection), I have still been pondering what I perceive as a shortcoming in the WPF Drag & Drop services.
Suddenly I realized that the start of dragging calls my code in order to get the data being dragged. I can do whatever I want there, including the triggering of any additional UI effects! With this, it seems a little silly to expect such functionality in the DragDrop class...
I need to write an excel-like grid that can have a lot of cells (400x400). All columns have the same width and all rows the same height. Each cell can contain text or be empty and each cell can have a column and/or row span. I suppose this will never work with the Grid panel and I suppose I will need UI virtualization in both column and row direction.
So my first try was to create a virtualizing grid by deriving from VirtualizingPanel and implement IScrollInfo. This could have "easily" be the solution except that I ran into a problem:
To provide IScrollInfo with the relevant information about scroll size and position and to be able to detemine wich items need to be created (realized) next using the ItemsContainerGenerator, I need to know the column index, row indeox and columnspan for each child item (cell). The only way I can think of to do this is using attach properties. The problem is: I can only read the values of attached properties if the ItemContainer that has them is already realized. So I am in a catch 22 here. To know what to realize I need to realize all items. To provide the data for IScrollInfo I need to realize all items.
So it seems that I am at a dead end with this approach.
Do you have any idea how I could implement a control like this or know how I could reslove the above problem?
It strikes me that you may not need to instanciate the UI elements themselves- you can very easily have a collection of DependencyObject-derived viewmodels, each of which has the WidthProperty and HeightProperty set (and possibly bound to the equivalent Width and Height properties of the visible cell UI element, once those are created).
Storing 160,000 (400x400) class instances shouldn't be a problem, especially if you are able to index into the set using row and column.
I have always been using a Syncfusion virtual grid which works on the basis of an override on that grid that is fired for each cell that is visible! It provides me with information on the row and column and some cell object that lets me set the value of that cell, its formatting, colours etc.
This allowed for very fast scrolling on very large datasets, since I simply have to 'read out' the value like dataSet.Tables[0].Rows[1000000]["LastName"].ToString()
Is there anything similar exposed by the WPF DataGrid?
EDIT
I need to make myself clearer - I know about virtualization and that it switches itself off when you do grouping etc. Having run a test with grouping enabled over a dataset of 20,000
rows made my grid choke on itself.
Therefore my previous question stands on its own!
Is there any way the grid allows me to fill in the text and do some formatting through some override or callback?
Thanks
The DataGrid uses virtualization by default. This works by either creating and deleting cells on the fly or by recycling the visible cells and repopulating them with the current row's data. This can be turned off as well as tweaked by playing with the 'VirtualizingStackPanel.VirtualizationMode' property and is forced off in many situations (grouping is a good example). This virtualization can be a godsend and a curse. If you have a simple set of requirements, then it makes it dead easy to get good performance. If on the other hand you are doing complex runtime binding, including triggers and custom columns, then it becomes a bit of a nightmare.
a couple of important reads:
http://msdn.microsoft.com/en-us/library/cc716879.aspx
http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx