Open arthur-clifford opened 2 years ago
Hi @arthur-clifford, I checked this out briefly. Are you aware of this example? http://6pac.github.io/SlickGrid/examples/example16-row-detail.html
There was some work done on integrating several rows to provide a space where a custom HTML layout could be rendered. Because the row height is fundamental to the grid, it would be very hard to allow custom row heights, but the aggregation of more than one row was tricky, but possible.
What you're doing looks good, but I'd need to check it out a bit more carefully before giving the green light.
Sorry this is a bit long guys. Hopefully its a good bathroom break read ;)
Code samples in this issue have -> arrows to indicate beginning and end of what I believe I added to relevant scripts.
A while back I did some customizations that I would eventually like to be able to share, especially along the lines of supporting custom rows. There are relatively simple tweaks to allow the genral capability. What I'm sharing here is to give an idea of the changes that are made and toward the end looking to make sure the approach is okay within your standars or if you have any suggestions for better approaches.
What I was attempting at the time was to be able to have custom rows in order to support a better summary tech where a summary (say sum or avg) end up as a row across all columns and the summary value for a column that summary has been enabled for has a value and those that don't are empty. I ended up allowing for sum, avg, median, min, max, and std dev. And I allowed for summaries + grouping. (The focus of this issue is custom row support not the aggregators per se, that's its own topic.
Here is an example of it working where summaries are shown for data with two groupings and avg applied to two columns and sum applied to 1.
Note: This requires a group summary title row (they have the calculator icon) as well as a row for each aggregation. Note also that summary values only show up for the appropriate columns and that summary name appears at the left.
Note: At the end of the grid here as you can see above each grouping has its own nested summary title and group summary rows, and at the end there is a Grand Summary Title Row and Grand Summary summary rows.
Though not depicted I also provide grid menu options for toggling on/off group- or grand- summary sections.
The changes to data view to support this were: (at the beginning of DataView)
Note, that alone if added would not break anything, but what it allows for is a section of grid parameters called customRows to be defined where an array of preRows and postRows may be returned from appropriate functions.
Then a change to the recalc function in DataView
Note: Again if the customizations aren't present this will have no effect other than a couple condition checks per item. What it is doing is adding custom rows before and after the normal row generation.
Changes to flattenGroupedRows
Changes to getItemMetadata
Note: grid uses the getItemMetadata to get groupItemMetadata info when valid. So this expand getItemMetatdata to allow for a more generic getRowMetadataProvider defined in grid dataView parameters.
When the pre and post rows are retrieved from the various customRow functions in the dataView or group options one of a few NonDataRow extension classes is used for the rows returned. These classes have an additional custom property and its value is a unique name for the row type. So providing a getItemMetadataProvider function custom rows can be handled by detecting if they have custom and then switching on the __custom property at which point the getItemMetadataProvider function provides an instance of ItemRowMetadata with the information needed by the grid or a plugin like the Excel exporter.
While one can argue this could be a different data view, there is very little that actually has to be done to the data view class to support custom rows as it already has support for non data rows and group rows. It is more of an issue of registering custom rows and, providng pre and post row functions for returning arrays of custom row instances, and providing an itemMetadataProvider which provides info; all of which can be done outside the grid in an application context.
Toward supporing this I did create a custom script I load for my project which is an adaptation of the slick.groupitemmetadataprovider.js. In fact it may have some residual commenting in it.
slick.custom.itemmetadataprovider.js
I defined my new custom row classes in a script: slick.custom.rows.js
So, I made this work, but I feel like the requestAnimationFrame trick at the beginning to wait for SlickGrid and NonDataRow to be defined before initializing them is a bit hacky. I am not sure if there are application context where the Slick.Custom stuff would not be registered in time for data to be displayed. In my application data displayed in the grid isn't retrieved until well after everything has been loaded and the user has interacted with a search UI or interacted with a map. It is different than example plugins you've provided because it is dependent on Slick and Slick.NonDataRow where as examples provided don't have such dependencies.
I'm wondering then if custom row support as I'm attempting it here is something a) you would like to see in SlickGrid, b) you feel there is a better approach to regarding allowing the Slick.Custom functionality? If you are open to these customizations I can fork a more recent version of the repo make the necessary tweaks and do a proper pull request. (I'm not sure when, but I'll do it.) And if I do .. which folder would you prefer I add the slick.custom.itemmetadataprovider.js script?