Magento - how to file an editable grid with mass action or similar

I am using a grid in magento to display the contents of a table. There is a position column in this table, and I sort the contents according to the value in it.
This position column is displayed as a 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 imagine the value of these columns for all rows? I tried using a bulk action, but only sent the id of the selected rows, not the position column. Is there any other way to do this?

+4
source share
3 answers

Try using 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 )); 
+2
source

try below in the 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 will not be able to publish these values. To post editable values ​​add javasctipt below 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 the 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); } 
0
source

Source: https://habr.com/ru/post/1385928/


All Articles