bernhard

RockGrid - powerful, performant and beautiful data listing tool

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

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip
    • By psy
      Background
      I'm creating a module to integrate https://pushalert.co/ into ProcessWire. You actually don't even need a module. You could just use the "Other Websites" javascript provided by PushAlert for basic functionality, ie send a broadcast notification to all subscribers. This is essentially what all the other integrations, including WordPress, do. The WP integration installs a widget with a form enabling the admin to enter details such as title, message, etc from a blog post. It does not:
      collect any statistics within the CMS about the notification enable audience fine tuning to eg a particular subscriber or subscriber segment within WP. The admin needs to use the PA dashboard for that functionality PushAlert has a javascript and REST API. It's intended that this module will use both. https://pushalert.co/documentation 
      What my module does so far:
      associate a subscription with a user. FE user clicks a button on the website front end to subscribe and/or agrees to the browser popup to accept notifications from this site send broadcast push alerts from a page within admin It doesn't have a 'widget' but easy enough to create a fieldsetpage with the relevant fields and add that fs page to any appropriate templates, then with a hook, send the notification. Need to be careful that once published/sent, the notification is not automatically re-sent on subsequent page edits.
      Looking for help/collaboration on how best:
      to send a notification, eg from a blog post, then track the statistics. Dilemma is that the push notification must come from the admin page. Responses go to the sending page which, as it's an admin page, is restricted and will not accept the https response. This is where the other CMS integrations stop. The only json response from PushAlert is the status, eg 'success', and the notification id. There is no opportunity at this point to capture the sending page id. handle, 'once sent on page publish', do not automatically resend on future page edits Am thinking along the lines that FS Page will have a @kongondo runtime markup field https://modules.processwire.com/modules/fieldtype-runtime-markup/ to pull the stats from PushAlert. Every time an admin visits the page, the stats will update.
      Once an admin checks the 'Send notification on page publish' checkbox, a hook creates new front end page that records the 'sender page', sends the notification request to PA, which then uses that newly created frontend page, as the response endpoint. Another rook re-associates the front end page with the admin page (eg blog post), to update the stats.
      Potential use cases:
      Notify individual and/or users with a particular role of an event, eg "New work opportunity" for job seekers; new blog post published; entries now open, etc...
      Looking for help/ideas/collaboration on this module. Please let me know if you're interested and as I do, believe this would be a great addition to ProcessWire