简体   繁体   English

如何在新窗口中打开杂货杂货中的自定义操作?

[英]How to open in a new window a custom action in grocery crud?

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? 我应该添加什么?

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). 您可以修改默认的杂货杂货,以添加一个jQuery处理程序(或者,出于某种原因,如果愿意,可以使用回调添加该处理程序)。

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"). 该jquery处理程序将建立某些确定的类的链接(例如,add_action生成的按钮的class属性可以为class =“ edit_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text- icon-primary“)在新窗口中打开(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"); //在此处添加在新窗口中打开链接所需的按钮类别$(“。YOUR_CLASS_NAME”)。attr(“ target”,“ _blank”);

Here's a quick trick to do the job without any changes in Grocery Crud CORE file. 这是在不对Grocery Crud CORE文件进行任何更改的情况下完成此工作的快速技巧。 Just add a call to str_replace() before you pass the output to your print function in your controller, eg: 在将输出传递到控制器中的打印功能之前,只需添加对str_replace()的调用即可,例如:

GC Theme: datatables GC主题:数据表

...
$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 GC主题: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" 以我为例,添加的动作具有给定的类/标题,但是您应该执行“查看源代码”并查看最终输出,然后找出在何处拼接target="_blank"

Solution source: GC forum 解决方案来源: GC论坛

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM