Grid with static data


#1

Hi,

I try to create a grid (to use sorting, ect.) with static data (no CRUD,no SQL, no database), but with an array.

How can I do this ?

This works with a table, but not with a grid: “Call to undefined method atk4\data\Persistence_Array::action()”
$grid = $app->add([‘Table’]);
$grid->setSource($array);

Any help ?

Thanks


#2

This have been significantly improved in :slight_smile:

While previously there were some hacks around it, now it simply relies on Persistence_Static, that have recently been added to Agile Data:

and documented here:

http://agile-data.readthedocs.io/en/develop/static.html?highlight=static


#3

Hi,
I tried the static persistance, it works with the table, but not with the grid:
my code:

$grid = $app->add([‘Table’]);
$grid->setModel(new \atk4\data\Model(new \atk4\data\Persistence_Static([
[‘VAT_rate’=>‘12.0%’, ‘VAT’=>‘36.00’, ‘Net’=>‘300.00’],
[‘VAT_rate’=>‘10.0%’, ‘VAT’=>‘52.00’, ‘Net’=>‘520.00’],
])));

-> Works

$grid = $app->add([‘Grid’]);
$grid->setModel(new \atk4\data\Model(new \atk4\data\Persistence_Static([
[‘VAT_rate’=>‘12.0%’, ‘VAT’=>‘36.00’, ‘Net’=>‘300.00’],
[‘VAT_rate’=>‘10.0%’, ‘VAT’=>‘52.00’, ‘Net’=>‘520.00’],
])));

-> Works not
Uncaught Error: Call to undefined method atk4\data\Persistence_Static::action()

any ideas ?


#4

This has been addressed in “develop” branch and should work with $grid->setSource($array);

oh and the issue with action - $grid = $app->add([‘Grid’, ‘paginator’=>false]);


#5

awesome ! it works now.
Next Challenge is:

  1. When I click on a header a full page reload is performed. Can I avoid this ?
  2. Sorting is not performed. How Can I achieve this ?

Thanks


#6

Array persistence does not support sorting, so for best results you should connect with a database model.

I’m not sure what do you mean with clicking a header.

Does it work as you expect on this page: http://ui.agiletoolkit.org/demos/crud.php ?


#7

Yes, the example you mentioned is exactly what I want to achieve.
Click on a grid header an get everything sorted.
But without a database :smile:
Is there a way to avoid the reload on click ?


#8

Try this: https://semantic-ui.com/collections/table.html#sortable

Default sorting is designed for large data volumes so limiting/sorting happens in the database.


#9

progessed now with Persistance_Array and ATK1.4.1
Awesome!

Thanks for this.