Topic: Grid Callback

hi there,

e.g. i have a list with some comments which i can edit. now i want, that anybody can only edit their own comments. here i ll need a custom callback to verify the ownership.

but how can i return a link, image etc. all custom html code will be printed in raw text.

is there a way without touching the core? can i return a column object? i tried but with no success.

i am sure u can help me (like always smile)

greez nico

Last edited by nkrueger (2012-01-24 10:05:41)

Re: Grid Callback

Hi nico,

first of all I always prefer to see a bit of code to better understand,
however..

... all custom html code will be printed in raw text...

this is not true for datagrid,  never for some fields on dataedit (container / free field).
basically a datagrid-column before output is "sanitized" using htmlspecialchars but not if you use a field  "pattern" or a callback function.

some code:

...
//by field name, in this case htmlspecialchars is applyed 
$grid->column('title','Title');

//by field pattern, in this case no so you can also output html
$grid->column('{title} <em>created:</em>{date}','Title and date');

//by callback, never in this one, so youre free to decide output in your method
$grid->column('body','Title and date')->callback('abbr',$this);
...

the last one, the callback way,  can be used also to check user and decide to return a "edit link" for users with right permissions. The callback example is on first page of rapyd framework
http://test.rapyd.com/grid/index

and if you have time.. 
in rapyd cms  there is a similar situation (user management, to prevent  root user deletion).

Re: Grid Callback

I ll try today.

thanks for your reply.

nico

// the root user delete prevention is a pre_process task

Last edited by nkrueger (2012-01-30 10:15:00)

Re: Grid Callback

field pattern is what i looked for. thanks a lot!

i tried it several times with callback and i know i had probs. i ll try this in a few day.

for now field pattern is excellent smile

Re: Grid Callback

me again.

i do need the callback smile

...
$grid->column(NULL,'')->callback('callback_free_item', $this);
...

function callback_free_item($row)
    {
        if($row["user_id"] == rpd::$auth->user('user_id'))
                return '<a href="/index.php/item/item_free/1002" onclick="return confirm(\'sure\')"><img src="/core/assets/switch.png"  style="vertical-align:middle" /></a>';
    }
...

i get the raw html command displayed sad

Re: Grid Callback

try to use a field pattern instead NULL or inside return string (it will be enough to skip htmlspecialchars)

Re: Grid Callback

I´ll try. But i have some cases, where i do not need a field column. there it wont work.
i had to escape the htmlspecialchars function in datagrid class for me 2 work.

another question:
am i able to set a custom style of a table row? i wont to color some rows per specific conditions (e.g. a value is 0 or >= 20)

Last edited by nkrueger (2012-02-06 09:37:04)