Question

What I want to do is that when I click the custom action in a table rendered using grocery crud it will open in a new window.

public function list() {
        try {
            $crud = new grocery_CRUD();

            $crud->set_theme('flexigrid');
            $crud->set_table('employee');

            $crud->add_action('Create Payslip', base_url().'design/images/img.png', 'roll/emp');

            $output = $crud->render();

            $this->output($output);
        } catch(Exception $e) {
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }
    }

What should I add?

Was it helpful?

Solution

You could modify the default grocery crud, to add a jquery handler (or you could add that using a callback if you prefer this for some reason).

This jquery handler will make the links of some determined class ( for example the class attribute of an add_action generated button can be class="edit_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" ) to open in a new window (target="_blank").

Your handler will be something like this:

//add here the class of the buttons you need to open links in a new window $(".YOUR_CLASS_NAME").attr("target", "_blank");

OTHER TIPS

Here's a quick trick to do the job without any changes in Grocery Crud CORE file. Just add a call to str_replace() before you pass the output to your print function in your controller, e.g.:

GC Theme: datatables

...
$crud->add_action('Print', '', 'admin/print_monthly_fess', 'ui-icon-print');
$output = $crud->render();

$output->output = str_replace('class="edit_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"', 'class="edit_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" target="_blank"', $output->output); //additional line
$this->_example_output('example_template.php', $output);

GC Theme: flexigrid

...
$crud->add_action('Print', base_url().'assets/grocery_crud/themes/flexigrid/css/images/print.png', 'admin/print_monthly_fess');
$output = $crud->render();

$output->output = str_replace('title="Print"', 'title="Print" target="_blank"', $output->output); //additional line
$this->_example_output('example_template.php', $output);

In my case the added action has the given class/title, but you should do a "view source" and take a look at the final output, then work out where to splice target="_blank"

Solution source: GC forum

Here i solved with jquery.

$(".gc-container").on("mouseenter", "a[href*='PartURLDistincAcction']", function(){
    $(this).attr('target', '_blank');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top