Question

I want to show a backend grid in system configuration tab. For that purpose I made a button and onClick I called the code written in controller and get block of 'grid.php' through Ajax. Here is the controller code

$this->getResponse()->setBody(   $this->getLayout()->createBlock('module/adminhtml_system_config_form_codegrid')->toHtml(),
         $serialize_block = $this->getLayout()->createBlock('adminhtml/widget_grid_serializer'),
         $serialize_block->initSerializerBlock('module/adminhtml_system_config_form_codegrid', 'getSelectedCode', 'code', 'selected_code')
    );

My Problem is the default Pagination and Filters are not working on grid. Fire Bug Show JS Errors. ReferenceError: code_gridJsObject is not defined

code_gridJsObject.loadByElement(this)

Was it helpful?

Solution

Make sure that $this->setUseAjax(true); is written in constructor of grid.php

The js code returned by Ajax call is not executable by default, you have to do something like

     var code = transport.responseText;  // Ajax returned text
     var fieldset= document.getElementById('Configuration_Field_Set_Name');
     fieldset.innerHTML = code;

    var arr = fieldset.getElementsByTagName('script') // Get All Script Tags  Returned by Ajax
    // Last Step
    for (var n = 0; n < arr.length; n++){
        eval(arr[n].innerHTML)
    }

Hope it will help !!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top