Jump to content

RockFinder3 - Combine the power of ProcessWire selectors and SQL


bernhard

Recommended Posts

RockFinder is just for pulling data from the database. We actually now have $pages->findRaw() which makes RockFinder obsolete in many cases.

The ->dump() method is just for debugging, but if you look into the code you can see how it's done. It uses tabulator.info to display the data that RockFinder pulls from the DB.

So you can quite easily build a Lister / ListerPro alternative with findRaw/RockFinder and tabulator. If you don't want to build it on your own you can write me a PM and buy a license of RockGrid, which was built exactly for that purpose, namely taking a RockFinder/findRaw result and turning it into a tabular grid with sorting and filtering capabilities:

EODtQXT.gif

But even when using my module you need to code your grid via JavaScript, so it's not a click-click solution. But it helps you to get setup quickly and to make the foundation well structured and future proof (maintainable) and it even creates the necessary boilerplate files for you (basically a PHP file for grabbing data via RockFinder and a JS file for setting grid options like sorting, column labels, column widths etc).

So you just need to click on "create new grid" and then edit these two files:

JS

$(document).on('RockGrid2', function() {
  let rg2 = RockGrid2;

  // this will add the grid using the default base setup
  // if you want to use another base setup set it as 3rd argument
  // see RockGrid2.js for more details
  rg2.add('Demo', {

    // here you can set any properties of your grid
    paginationSize: 15,

    // column definitions
    autoColumnsDefinitions:function(definitions) {

      // loop all definitions and set column settings
      definitions.forEach((col) => {
        let name = col.field;

        // example how to use the link() helper
        if(name == 'id') {
          col.width = 50;
          col.hozAlign = 'center';
          col.formatter = function(cell) {
            let id = cell.getValue();
            return rg2.link({
              icon: 'edit',
              href: rg2.editUrl(id),
              tooltip: 'Edit this page',
              panel: true,
            });
          }
        }

        // example how to use a predefined coldef
        // you can use this technique with your own coldefs as well
        if(name == 'title') {
          rg2.setColDef(col, 'edit');
        }

      });
      return definitions;
    },
  });
});

PHP

<?php

namespace RockGrid2;

class Demo extends Grid
{

  public function info()
  {
    return parent::info()->setArray([
      'title' => 'Demo Grid',
      'icon' => 'check',
    ]);
  }

  public function getData()
  {
    // we use findRaw in this example because it is shipped with the core
    // my recommendation is to use RockFinder3 as it provides a lot more
    // and customized options for working with PW page data in grids
    $data = $this->findRaw("id>0, limit=50, sort=-id", [
      'id',
      'title',
    ]);
    bd($data);
    return $data;
  }

  public function isViewable()
  {
    // who has access to this grid?
    return true;
  }
}

 

Link to comment
Share on other sites

  • 3 weeks later...

Hello,
How to output data in template ? no result using foreach();
it is working when using findRaw.

$items = $rockfinder->find("parent=/foo/")->addColumns(['title','text','date',]);
//d($items);
foreach ($items as $item) {
  echo $item['title'].$item['text'].$item['date'];
}

 

Link to comment
Share on other sites

You have to use getRows()

$items = $rockfinder->find("parent=/foo/")->addColumns(['title','text','date',]);
//d($items);
foreach ($items->getRows() as $item) {
  echo $item->title.$item->text.$item->date;
}

and the result will be objects, you have to use "->" instead of the square brackets

  • Like 2
Link to comment
Share on other sites

18 hours ago, zoeck said:

You have to use getRows()

$items = $rockfinder->find("parent=/foo/")->addColumns(['title','text','date',]);
//d($items);
foreach ($items->getRows() as $item) {
  echo $item->title.$item->text.$item->date;
}

and the result will be objects, you have to use "->" instead of the square brackets

Excellent !
Yes it's worked, thank you.

In my case rockfinder3 about 4 times faster than findRaw 🤩, and usefull feature is empty data automatically become NULL, so no need further work. 👍

Link to comment
Share on other sites

2 hours ago, pwfans said:

In my case rockfinder3 about 4 times faster than findRaw 🤩, and usefull feature is empty data automatically become NULL, so no need further work. 👍

Great to hear that, thx for sharing! I'm quite surprised, but that's a nice example that it makes sense to keep it alive besides findRaw 🙂 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...