Jump to content

[deprecated] RockGrid - powerful, performant and beautiful data listing tool


bernhard

Recommended Posts

Earlier in this topic I asked about autoHeight for rows. Now I have created a nice and only slightly hacky solution for it (no hacks in libs, just working around stuff). The existing simple option is not acceptable in our use case, because even the official docs say:

Quote

For large data grids (eg 10,000+ rows) the time taken to calculate the heights may take to long and you may decide not to use the feature in these circumstances. The row limit depends on your browser choice, computer speed and data so you will need to decide for yourself how much data is to much for this feature.

When using autoHeight for 35k rows, I got twice the message "the web page seems to be running slow, do you want to stop it". I don't even dare to imagine what would happen on an old smartphone.

The obvious (to me) solution was to calculate automatic height on demand only for the handful of rows displayed at a time. This has to happen on page load, on filtering and on pagination navigation. Due how pagination is implemented, a hoop had to be jumped through with it as well (to avoid an infinite loop). To be clear: the ag-Grid API offered no immediately useful event I could listen to! viewportChanged sounded like it would work, but in practice it failed to cover page navigation.

var paginationAttached = false;
var paginationHandler = function (event) { rowHeighter(grid, event); }
function rowHeighter(grid, event) {
    // calculate row height for displayed rows to wrap text
    var cols = [ grid.gridOptions.columnApi.getColumn("code"), grid.gridOptions.columnApi.getColumn("variation") ];
    grid.gridOptions.api.getRenderedNodes().forEach(function(node) {
        node.columnController.isAutoRowHeightActive = function() { return true; };
        node.columnController.getAllAutoRowHeightCols = function() { return cols; };
        node.setRowHeight(grid.gridOptions.api.gridOptionsWrapper.getRowHeightForNode(node));
    });
    
    // if listening to paginationChange, onRowHeightChanged creates an infinite loop, so work around it
    if(paginationAttached === false) {
        grid.gridOptions.api.onRowHeightChanged();
        grid.gridOptions.api.addEventListener('paginationChanged', paginationHandler);
        paginationAttached = true;
    } else {
        grid.gridOptions.api.removeEventListener('paginationChanged', paginationHandler);
        grid.gridOptions.api.onRowHeightChanged();
        grid.gridOptions.api.addEventListener('paginationChanged', paginationHandler);
    }
}

You can see here that I had to brute-force overwrite a couple of functions in the ag-Grid row height calculation logic. I define the columns I want to target for the auto height and trick the getAllAutoRowHeightCols to just provide them.

My filter event listener in RockGridItemAfterInit is

grid.gridOptions.api.addEventListener('filterChanged', function(event) { rowHeighter(grid, event); });

A CSS rule is also required:

div[col-id="variation"].ag-cell, div[col-id="code"].ag-cell {
    white-space: normal;
}

Using automatic row heights brought about an issue with the default fixed height grid: a wild scrollbar appeared! I found out I can make the grid height adapt, putting this into RockGridItemBeforeInit:

// pagination with a fixed number of rows and adapting grid height
grid.gridOptions.paginationAutoPageSize = false;
grid.gridOptions.paginationPageSize = 15;
grid.gridOptions.domLayout = 'autoHeight';

Then I decided the pagination controls should live above the grid, because otherwise their position will change annoyingly whenever the grid height changes. Putting this into RockGridItemAfterInit:

// move the pagination panel to the top, because the dynamic row heights would change its position at the bottom
var pagingPanel = document.querySelector('.ag-paging-panel');
var rootWrapper = document.querySelector('.ag-root-wrapper');
rootWrapper.prepend(pagingPanel);

 

  • Like 2
Link to comment
Share on other sites

9 minutes ago, bernhard said:

Thx for sharing that @Beluga! Do you think the aggrid core team could be interested in your solution? Maybe they can implement it somehow?

I just now went looking in their issue trackers and found this in their enterprise support tracker (in category tab "Standard Feature Requests):

AG-1202 Allow rendering rows dynamically adapting their height to their content

That does sound like what I want, but thanks to their closed system, we have no way of knowing the exact contents of the issue! ???

There is also this, which would only be for paying customers:

Enterprise Row Model AG-1039 Allow dynamic row heights and maxBlocksInCache

This is in Parked category:

AG-2228 Allow lazy loading of rows when using autoHeight, ie on scroll to configured amount of rows, append n more rows at the bottom

So looks like this stuff is on their radar (which I would have assumed based on how they acknowledge the pain point in their docs). Let's wait and see and for now enjoy my hack ? All this hacking does have the effect of improving my self-confidence and wanting to learn JS more deeply ?

  • Like 2
Link to comment
Share on other sites

Hi

I discovered ag-grid documentation (since I solved all my Rockfinder problems, thanks!). I have really general questions.

  • How I should decide what to put in BeforeInit vs AfterInit? For example, why the visible/hidden column are in AfterInit?
  • I want to have a modified version of YesNo plugin. How I can do that? For now, I rename with a slightly different name and add it in /assets/Rockgrid folder. Is it the good way to do it (it works BTW)?
  • Where I should put CSS file? I added in /assets/Rockgrid/style.css and link into my PHP file. However, for some reasons, I'm not able to use row classes. The class is well added in html but CSS classes's are overridden. However If I used instead inline CSS directly in the JS file, the row is correctly styled.
  • I have many Rockgrid fields, sharing some columns. How I can define some common column headers (definition, style, etc..) instead of re-write on each field.js file?

Thanks!

Mel

Link to comment
Share on other sites

7 hours ago, mel47 said:

How I should decide what to put in BeforeInit vs AfterInit? For example, why the visible/hidden column are in AfterInit?

Usually it's fine to put everything in BeforeInit. Sometimes AfterInit is needed (for example if you have dynamic columns calculated on runtime).

7 hours ago, mel47 said:

I want to have a modified version of YesNo plugin. How I can do that? For now, I rename with a slightly different name and add it in /assets/Rockgrid folder. Is it the good way to do it (it works BTW)?

Yes, that's fine.

7 hours ago, mel47 said:

Where I should put CSS file? I added in /assets/Rockgrid/style.css and link into my PHP file. However, for some reasons, I'm not able to use row classes. The class is well added in html but CSS classes's are overridden. However If I used instead inline CSS directly in the JS file, the row is correctly styled.

CSS should be loaded automatically: https://github.com/BernhardBaumrock/FieldtypeRockGrid/tree/master/plugins#creating-custom-plugins; I don't know why your css classes are overwritten, sorry.

8 hours ago, mel47 said:

I have many Rockgrid fields, sharing some columns. How I can define some common column headers (definition, style, etc..) instead of re-write on each field.js file?

See the readme here https://github.com/BernhardBaumrock/FieldtypeRockGrid/tree/master/coldefs

And a very simple example https://github.com/BernhardBaumrock/FieldtypeRockGrid/blob/master/coldefs/fixedWidth.js

You can then just use col = RockGrid.colDefs.yourColdefName(col); in BeforeInit

Link to comment
Share on other sites

  • 1 month later...
On 9/24/2018 at 4:04 PM, Beluga said:

I like RockGrid very much and the new smart filter is a really nice addition. I will look into paying you after we launch the site.

Thank you Beluga! Just received your generous donation ? Really appreciated! Thx! Glad if it helped you for your project even if it seems that you switched to another library now?! Thank you for all your feedback and contributions to this project!

Link to comment
Share on other sites

2 hours ago, bernhard said:

Thank you Beluga! Just received your generous donation ? Really appreciated! Thx! Glad if it helped you for your project even if it seems that you switched to another library now?! Thank you for all your feedback and contributions to this project!

Well, RockGrid and RockFinder are still essential to make it work with PW no matter which JS lib we use ?

I will look into donating to Tabulator next to cover all bases.

Regarding the earlier discussion about creating a module that makes RockGrid and Apex Charts talk to each other: I might look into it after my plate is cleared of various stuff (such as launching this proverb project).

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

The new rockfinder updates make it easy to extend grids:

Extending Grids

Sometimes several RockGrids are very similar and you don't want to duplicate your code. You can create one base file and include this file from others:

// trainings.php
$finder = new RockFinder([
  'template' => 'training',
  'sort' => 'from',
], [
  'first',
  'from',
  'to',
]);
$finder->addField('coach', ['title']);
$finder->addField('client', ['fullname']);

// trainings_booked.php
include(__DIR__.'/trainings.php');

$finder->setSelectorValue('client', $this->user); // only show trainings of current user
$finder->addField('done'); // add column to show if the training was completed

$this->setData($finder);

You can then create another file, for example trainings_available.php to show all trainings that are in the future and available for booking:

include(__DIR__.'/trainings.php');

$finder->setSelectorValue('from>', time());
$finder->setSelectorValue('client', null); // client must not be set -> means available for booking

$this->setData($finder);
  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

Hi,

New problem but I'm quite sure it was not there before, but I don't know since when. I upgrade to last version 1.1.1 but didn't help. I get this error. The grids (more than 1 with different queries) appear with "loading" but nothing happens. Error is from Chrome, but same one in Firefox.

(index):2 Uncaught SyntaxError: Unexpected token W in JSON at position 1 at JSON.parse (<anonymous>) at XMLHttpRequest.xhr.onreadystatechange (RockGridItem.js?t=1550464515:271)

Thanks

 


 
 
Link to comment
Share on other sites

On 6/30/2018 at 5:38 PM, bernhard said:

Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour (excl vat).

Hi mel47,

sorry to hear that. Check your finder with RockFinderTester, maybe it is somehow broken. If that does not work you can write me a PM support request and maybe provide a login to your system so that I can check what is going on. You need to make sure that the response of the AJAX requests are valid JSON. Also check all your error logs, maybe you find some helpful information there.

  • Like 1
Link to comment
Share on other sites

On 2/18/2019 at 12:01 AM, mel47 said:

Hi,

New problem but I'm quite sure it was not there before, but I don't know since when. I upgrade to last version 1.1.1 but didn't help. I get this error. The grids (more than 1 with different queries) appear with "loading" but nothing happens. Error is from Chrome, but same one in Firefox.

(index):2 Uncaught SyntaxError: Unexpected token W in JSON at position 1 at JSON.parse (<anonymous>) at XMLHttpRequest.xhr.onreadystatechange (RockGridItem.js?t=1550464515:271)

Thanks

 



 
 

Solved. Had to return in PHP7.1 because zlib is "on" instead of "off" on my server when set to PHP7.2.

 

Link to comment
Share on other sites

  • 1 month later...

Just added support for tippy.js to show nice tooltips with additional information. For example here I needed to show all available invoices related to one project of one month and I don't want different line heights, so I show the links on hover:

ajvRWQQ.png

Using tippy.js

img

col = grid.getColDef('ids');
col.headerName = 'Rechnung';
col.cellRenderer = function(params) {
  if(!params.value) return '';
  var ids =  params.data.ids.split(',');
  var out = 'IDs: ' + ids.join(', ');
  var tippy = 'One per line:<br>' + ids.join('<br>');
  return RockGrid.tippy(out, tippy);
}
  • Like 6
Link to comment
Share on other sites

  • 2 weeks later...

If I want to show tens of thousands of rows, but just 100 per page, the only options I have at the moment are:

  • Load all rows and let agGrid handle the pagination (fast navigation, slow initial load)
  • Just show 100 results (fast initial load, but data is incomplete)
  • implement my own server side ajax implementation for pagination (fast, but higher development effort)

Is that right? Or does RockFinder already provide a solution for pagination without having to load all the data? If it doesn't: Is that something that falls in the scope of RockFinder and you @bernhard would like it to be implemented?

Link to comment
Share on other sites

Hi @MrSnoozles

you are right - RockGrid is intended to load all data to the client at once. Doing this via paginated ajax calls would have a lot of side effects and is not planned. For example if you have column statistics showing the sum of all rows, that would not be possible when data was paginated (and not fully loaded into the grid). Also sorting would work totally different. aggrid supports this feature, but it would need a LOT more work to also support this in RockGrid. Not only for development of RockGrid but also for development of every single field/grid.

When I have complex queries then I usually display only a subset of the data, for example all entries of year XXXX. You can see some performance tests here:

 

 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Just had a very interesting conversation with @wbmnfktr and wanted to share this little preview of a quite big upgrade coming soon called "RockGridActions". I'll share some more infos soon. The great thing about it is that it is built modularly so that we'll be able to use it almost plug&play for RockTabulator ( @Beluga)

  • Like 14
Link to comment
Share on other sites

@bernhard Thanks for the great module! Just started to use in in a project and it has helped me save a ton of time!

Is it possible to create a grid just by PHP? Saw that there was a Javascript possibility but i would need to create grid from a form submit.

Link to comment
Share on other sites

Hi @gottberg

glad to hear that. Sometimes I feel that the potential of this or similar modules is underestimated. If you only need a HTML grid (table) then you might be better off using MarkupAdminDataTable. RockGrid is by design a grid with user input like filtering and sorting and custom colorizations based on cell values. If you don't need all that just create a plain html table.

Does that help?

Link to comment
Share on other sites

1 minute ago, bernhard said:

Hi @gottberg

glad to hear that. Sometimes I feel that the potential of this or similar modules is underestimated. If you only need a HTML grid (table) then you might be better off using MarkupAdminDataTable. RockGrid is by design a grid with user input like filtering and sorting and custom colorizations based on cell values. If you don't need all that just create a plain html table.

Does that help?

Thanks for fast reply! Well in this case i would want the export to csv which would be convenient since the project uses RockGrid for many of the listings. ? I could save the form to a own template which would only be updated on submit, then i would get the export feature too ?

Link to comment
Share on other sites

Sorry, I don't get what you are saying ? 

BTW: Of course you can just show a simple grid without modifying it via javascript. That's explained in the quickstart: https://github.com/BernhardBaumrock/FieldtypeRockGrid/wiki/Quickstart (actually there is nothing to explain if you don't use any javascript modifications). But as soon as you want to style or tweak your grid (eg custom Headernames) you need javascript.

Would be happy to see some screenshots so maybe others do also get inspired by your work ? 

Link to comment
Share on other sites

21 hours ago, bernhard said:

Sorry, I don't get what you are saying ? 

BTW: Of course you can just show a simple grid without modifying it via javascript. That's explained in the quickstart: https://github.com/BernhardBaumrock/FieldtypeRockGrid/wiki/Quickstart (actually there is nothing to explain if you don't use any javascript modifications). But as soon as you want to style or tweak your grid (eg custom Headernames) you need javascript.

Would be happy to see some screenshots so maybe others do also get inspired by your work ? 

I meant that i would create a template to which the form would be submited so that i could use RockGrid as usual. I did that and i works great for this use! ? 

I would love to share but since its for the customers internal use im not allowed to share anything.. ?

Once again thank you! 

Link to comment
Share on other sites

38 minutes ago, gottberg said:

I meant that i would create a template to which the form would be submited so that i could use RockGrid as usual. I did that and i works great for this use! ? 

Still don't get it. We have forms all over PW (and the web), so it's hard to guess which one you are talking about... and I have also no idea what you mean by using RockGrid "as usual" - but I'm curious: Are you using it on the Frontend?

Link to comment
Share on other sites

54 minutes ago, bernhard said:

Still don't get it. We have forms all over PW (and the web), so it's hard to guess which one you are talking about... and I have also no idea what you mean by using RockGrid "as usual" - but I'm curious: Are you using it on the Frontend?

Sorry, im bad at explaining. It's a backend module and i use RockGrid to display lots o different data. The data is loaded from PW.

The question i had from the beginning was if i could create a RockGrid with plain PHP. 

The module has a form that gets submited with data, and i wanted to create a RockGrid just with the POST data, that originally was not getting saved.

Now the data gets saved to a page and i can easily use RockGrid with that data.

Small offtopic question: Can i change the separator to comma somehow?

Thanks!

Link to comment
Share on other sites

Ok thx, now I get it ? I've planned that feature, but can't remember that I've ever used it, so I don't know if that still works (see option 2, InputfieldRockGrid.module.php):

7QtbN2e.png

1 hour ago, gottberg said:

Small offtopic question: Can i change the separator to comma somehow?

If you are talking about excel export: yes. I don't have any sample code, see /plugins/buttons/excel.js

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...