New Grid Column Types – "button" and "ask"

Thursday, April 22nd, 2010|Beginner tips, Version 3|by Romans

With the migration to jQuery (UI) we have received lot of new fancy functionality, but some of the old things stopped worked too. However old stuff is fixable, and if there is anything – please let me know by commenting and I’ll give it a fix.

This tip explains how you can add buttons to the grid. You can see working demo here:

First you need to add a grid with this code:


And we will need to also add 2 columns to demonstrate new features:

  $g->addColumn('button','poke','Poke user');
  $g->addColumn('prompt','message','Send message');

New column types are implemented inside lib/Grid.php and when clicked they will send ajaxec() request back to the same page with argument same as column name containing ID of the record. We need to properly handle that and return javascript output:

     $this->js()->univ()->alert('You have just poked '.$this->sample_grid_data[$_GET['poke']-1]['name'])->execute();
$this->js()->univ()->alert('You have sent message '.$_GET['value'].' to '.$this->sample_grid_data[$_GET['message']-1]['name'])->execute();

You can inspect how the formatters are implemented in lib/Grid and you can add your own grid column to add your own interactions.


Posted April 23, 20108:00 am

link seems missing /
also, alerts not show up in safari.

just to clarify, _GET['poke'] would contain row id on which button was added?

Posted April 26, 20102:49 pm

thanks. Link fixed.

Yes, all grids rely on having field ‘id’ in result set. It is automatically passed on many operations.

alerts show up fine in my safari, can you dig up more information? what does inspector say?

Svetlozar Kondakov
Posted April 27, 20103:32 pm

This seems a very clear way for me of adding buttons to the grid. However the things that are not working are makeSortable, format_inline and format_delete :)

Posted April 28, 20101:39 am

will be fixed soon.