5

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?

Minesh Patel
  • 541
  • 1
  • 6
  • 13
clem
  • 3,345
  • 1
  • 22
  • 33
  • Are you looking to submit the position column of selected rows along with the selected row IDs? – Lee Saferite Dec 18 '11 at 20:08
  • yes, that's what I'm trying to do – clem Dec 19 '11 at 09:39
  • 2
    Unfortunately I don't have the time to respond with a proper answer right now so I'll just say, you need to look at adminhtml/widget_grid_serializer and find usages of it in the core code/layouts. That is how they do exactly what you want to do. – Lee Saferite Dec 21 '11 at 21:06

3 Answers3

2

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
));
Allan MacGregor
  • 924
  • 6
  • 13
  • thanks for your reply Allan. this makes it editable but I still can't find a way to submit my grid with the edited values. any suggestions? – clem Dec 19 '11 at 15:41
1

You may find your answer here:

Magento admin grid sending data from Action to Controller

http://alanstorm.com/magento_admin_controllers

Community
  • 1
  • 1
B00MER
  • 5,471
  • 1
  • 24
  • 41
  • thanks for the reply, but I would need something that submits the whole grid, not just a single row – clem Dec 12 '11 at 17:52
0

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);
}
Minesh Patel
  • 541
  • 1
  • 6
  • 13