Magento - 如何提交具有批量操作或类似操作的可编辑网格

发布于 2024-12-20 23:13:40 字数 466 浏览 2 评论 0原文

我在 magento 中使用网格来显示表格的内容。该表有一个位置列,我根据其中的值对内容进行排序。
此位置列在网格中显示为类型输入:

    $this->addColumn('position', array(
        'header'    => Mage::helper('postcard')->__('Position'),
        'align'     =>'left',
        'index'     => 'position',
        'type'      => 'input',
        'width'     =>  '100',
        'sortable'  => true,
    ));

如何提交所有行的这些列的值?我尝试使用批量操作,但这仅提交所选行的 ID,而不提交位置列。还有其他方法可以做到这一点吗?

I'm using a grid in magento to display the content of a table. This table has a position column and I'm sorting the content according to the value in there.
This position column is displayed as type input in the grid:

    $this->addColumn('position', array(
        'header'    => Mage::helper('postcard')->__('Position'),
        'align'     =>'left',
        'index'     => 'position',
        'type'      => 'input',
        'width'     =>  '100',
        'sortable'  => true,
    ));

How can I submit the value of these columns for all rows? I tried using mass action but that only submits the ID of the selected rows and not the position column. Is there any other way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叹梦 2024-12-27 23:13:40

尝试使用以下代码代替

$this->addColumn('position', array(
    'header'    => Mage::helper('postcard')->__('Position'),
    'align'     =>'left',
    'index'     => 'position',
    'type'      => 'number',
    'width'     =>  '1',
    'sortable'  => true,
    'editable'  => true
));

Try with the following code instead

$this->addColumn('position', array(
    'header'    => Mage::helper('postcard')->__('Position'),
    'align'     =>'left',
    'index'     => 'position',
    'type'      => 'number',
    'width'     =>  '1',
    'sortable'  => true,
    'editable'  => true
));
风和你 2024-12-27 23:13:40

在您的网格列中尝试以下

$this->addColumn('position', array(
    'header'    => Mage::helper('postcard')->__('Position'),
    'align'     =>'left',
    'index'     => 'position',
    'type'      => 'input',
    'width'     =>  '100',
    'sortable'  => true,
    'editable' => 'true',
    'inline_css'     => "my-grid-input-text", // use this class to adjust input width using CSS
 ));

您的输入将是可编辑的,但您无法发布此值。
要发布您的可编辑值,请在 javasctipt 下方添加以覆盖默认函数

varienGridMassaction.prototype.apply = function() {
        if(varienStringArray.count(this.checkedString) == 0) {
                alert(this.errorText);
                return;
            }

        var item = this.getSelectedItem();
        if(!item) {
            this.validator.validate();
            return;
        }
        this.currentItem = item;
        var fieldName = (item.field ? item.field : this.formFieldName);
        var fieldsHtml = '';

        if(this.currentItem.confirm && !window.confirm(this.currentItem.confirm)) {
            return;
        }

        this.formHiddens.update('');
        new Insertion.Bottom(this.formHiddens, this.fieldTemplate.evaluate({name: fieldName, value: this.checkedString}));
        new Insertion.Bottom(this.formHiddens, this.fieldTemplate.evaluate({name: 'massaction_prepare_key', value: fieldName}));

        // collect all inputs of grid to post it
        new Insertion.Bottom(this.formHiddens, this.fieldTemplate.evaluate({name: 'form_inputs', value: Form.serializeElements($('#'+this.grid.containerId + ' .grid input'))}));

        if(!this.validator.validate()) {
            return;
        }

        if(this.useAjax && item.url) {
            new Ajax.Request(item.url, {
                'method': 'post',
                'parameters': this.form.serialize(true),
                'onComplete': this.onMassactionComplete.bind(this)
            });
        } else if(item.url) {
            if(item.target) {
                switch(item.target){
                    case '_blank':
                        this.form.target = '_blank';
                        break;
                    default:
                        this.form.target = '';
                        break;
                }
            }
            this.form.action = item.url;
            this.form.submit();
            this.form.target = '';
        }
 }; 

并在控制器文件中获取您的输入

$postData = $this->getRequest()->getParams();
if(isset($postData['form_inputs'])) {
    parse_str($postData['form_inputs'],$formInputs);
    echo "<pre>";
    print_r($formInputs);
}

try below in your grid column

$this->addColumn('position', array(
    'header'    => Mage::helper('postcard')->__('Position'),
    'align'     =>'left',
    'index'     => 'position',
    'type'      => 'input',
    'width'     =>  '100',
    'sortable'  => true,
    'editable' => 'true',
    'inline_css'     => "my-grid-input-text", // use this class to adjust input width using CSS
 ));

Your input will be editable but you can not post this values.
To post your editable values add below javasctipt to overwrite default function

varienGridMassaction.prototype.apply = function() {
        if(varienStringArray.count(this.checkedString) == 0) {
                alert(this.errorText);
                return;
            }

        var item = this.getSelectedItem();
        if(!item) {
            this.validator.validate();
            return;
        }
        this.currentItem = item;
        var fieldName = (item.field ? item.field : this.formFieldName);
        var fieldsHtml = '';

        if(this.currentItem.confirm && !window.confirm(this.currentItem.confirm)) {
            return;
        }

        this.formHiddens.update('');
        new Insertion.Bottom(this.formHiddens, this.fieldTemplate.evaluate({name: fieldName, value: this.checkedString}));
        new Insertion.Bottom(this.formHiddens, this.fieldTemplate.evaluate({name: 'massaction_prepare_key', value: fieldName}));

        // collect all inputs of grid to post it
        new Insertion.Bottom(this.formHiddens, this.fieldTemplate.evaluate({name: 'form_inputs', value: Form.serializeElements($('#'+this.grid.containerId + ' .grid input'))}));

        if(!this.validator.validate()) {
            return;
        }

        if(this.useAjax && item.url) {
            new Ajax.Request(item.url, {
                'method': 'post',
                'parameters': this.form.serialize(true),
                'onComplete': this.onMassactionComplete.bind(this)
            });
        } else if(item.url) {
            if(item.target) {
                switch(item.target){
                    case '_blank':
                        this.form.target = '_blank';
                        break;
                    default:
                        this.form.target = '';
                        break;
                }
            }
            this.form.action = item.url;
            this.form.submit();
            this.form.target = '';
        }
 }; 

and in controller file get your inputs

$postData = $this->getRequest()->getParams();
if(isset($postData['form_inputs'])) {
    parse_str($postData['form_inputs'],$formInputs);
    echo "<pre>";
    print_r($formInputs);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文