How to load another page in another column on grid button click

95 views
Skip to first unread message

Gowrav

unread,
May 23, 2012, 9:26:46 AM5/23/12
to Agile Toolkit Development
Hi there,
using new 4.2.1 and I have a page with two columns and a grid on first
column. there is a button on grid which i want if clicked should open
another page in another column on same page.. by sending row id

this is what I am doing right now

class page_scholar_fee_manage extends Page {

function init() {
parent::init();

$columns = $this->add('columns');
$left = $columns->addColumn();
$right = $columns->addColumn();


$students = $left->add('MVCGrid');
$students->setModel('Model_Scholar_Current');

$dtbtn=$students->addColumn('button', 'student_id');

$reload_right_action=$right->js()-
>reload(array('showassociated_fee'=>rand(0,1000)));
$dtbtn->js('click',$reload_right_action);

if($_GET['showassociated_fee']){
$right->add('Text')->set($_GET['showassociated_fee']);
}


}

}

but getting some error ....

Romans Malinovskis

unread,
May 23, 2012, 9:48:07 AM5/23/12
to agile-too...@googlegroups.com
Hi.

Here is your solution:


Because you’ll see that the page linked here has about a thousand entries, agile toolkit does not create object for every row of the grid. Instead it repeats the button’s markup and initializes all the buttons with a single js statement.

When button is clicked, it automatically sends AJAXec request to the page asking what to do next. 


If this code is useful, please tweet / share it. 

Regards,
Romans

--
FYI: If amount of emails you receive from this group is too much - switch to "Digest" mode. You'll receive no more than 1 email per day.

To post to this group, send email to
agile-too...@googlegroups.com

To unsubscribe and view archive:
http://groups.google.com/group/agile-toolkit-devel?hl=en

To download Agile Toolkit, visit:
http://agiletoolkit.org/

Gowrav

unread,
May 23, 2012, 2:06:07 PM5/23/12
to agile-too...@googlegroups.com
Hi Romans,
Loves your quick reply....

I also did this way.. but here are two ajax  requests ... one executing another hence two server cycles ....
I want a client side JS running on button click asking to page reload by giving the the ID of row as input param...

Just it saves one cycle to server ..

Romans Malinovskis

unread,
May 23, 2012, 2:58:37 PM5/23/12
to agile-too...@googlegroups.com
Hi.

In this case you’ll need to write your own column formatter. Remember that you are in an object-oriented framework. You can extend Grid class, override init_button(){} with an empty function and the default AJAX behavior will be changed. 


replace this with your code, something like:


class ScholarGrid extends Grid {
    function init_button($field){
        @$this->columns[$field]['thparam'].=' style="width: 40px; text-align: center"';
        $this->js(true)->find('.button_'.$field)->button();
$this->js(‘click’, $rightcolumn->js()->reload(array(‘id’=> $this->js()->_selectorThis()->closest(’tr’)->attr(‘rel’))) )->selector(‘#’.$this->name.’ button_’.$field);
    }

    function format_button($field){
        $this->current_row_html[$field]='<button type="button" class="'.$this->columns[$field]['button_class'].'button_'.$field.'" '.
            '\')">'.
                (isset($this->columns[$field]['icon'])?$this->columns[$field]['icon']:'').
                $this->columns[$field]['descr'].'</button>';
    }

This solution is quite hardcore for your first use of Agile Toolkit, that’s why I suggested to go with default two-AJAX requests. With this new code (i haven’t tested it) you will produce a javascript like this:


 $(‘#gridname button_student_id’).click(function(){ $(‘#id_of_rightside’).univ().atk4_load( ‘/path/to/page’, ‘id’=>$(this).closest(’tr’).attr(‘rel’) ) });

If you struggle to get this working, give me a shout and I’ll create an example for that. 



Reply all
Reply to author
Forward
0 new messages