Grid addSelectable get items

How to get selected item
// $grid->js(true)->_selector(’.ui-selected input’)->val()] it not work

$grid->addSelectable(‘id’,‘Select’);
$save = $grid->addButton([‘Save’, ‘icon’ => ‘ok’])->addClass(‘atk-swatch-green’);
$save->js(‘click’)->univ()->dialogURL(‘Selected items’, $this->api->url(‘payment’, [‘type’=>‘payment-type’,‘reload_view’ => $grid->name,‘vals’=>$grid->js(true)->_selector(’.ui-selected input’)->val()]),[‘ok_label’=>‘Confirm’]);

Hello you can use this code sequence to archieve what you want. I am using a form submit instead of a save button and a “hidden” field to save the values. You can hide the field via JavaScript, this line is commented out.

    // add grid
    $grid = $this->add('Grid');

    $grid->addColumn('id');
    $grid->addColumn('email');
    $grid->addColumn('password');

    $grid->setSource([
            ['id'=>1, 'email'=>'jon@doe.de', 'password'=>'abc123'],
            ['id'=>2, 'email'=>'martin@example.com', 'password'=>'xyz'],
    ],['id','email','password']);

    // form
    $f = $this->add('Form',null,null,['form_empty']);
    // add a form element to store the values in json
    $f->addField('line','productids')
      ->setCaption('');
    // hide th element
    //$f->getElement('productids')->js(true)->hide();

    // selectable column
    $grid->addSelectable($f->getElement('productids'));
    
    // save button
    $f->addSubmit('Save')->setNoSave();
    
    
    /*************************** process form *****************************/
    if($f->isSubmitted())
    {
       $this->js(TRUE)->univ()->dialogURL('Selected items', $this->api->url('payment', ['type'=>'payment-type','reload_view' => $grid->name,'vals'=>$f->get('productids')]),['ok_label'=>'Confirm'])->execute();

    }

Hello, you can use this code to make Grid Selectable and Get the Selected Row Id’s in array

/*Step 1: First Add Form */
$form = $this->add(‘Form’);
$selected_row_field = $form->addField(‘text’,‘selected_row’);
$form->addSubmit(‘Update’);

/*Step 2: Add Grid */
$grid=$this->add(‘Grid’);
$grid->setModel($model); //Here $model is your Model Object
$grid->addSelectable($selected_row_field); //Make Grid Selectable

/*step 3: Form Submission Handeling */
if($form->isSubmitted()){
$selected_row_array = json_decode($form[‘selected_row’],true);
}

Thank you @philipp_palmtag and @rksinha_btech :slight_smile: