kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

Get Selected Rows #58

Closed dudunegrinhu closed 9 years ago

dudunegrinhu commented 9 years ago

Kartik,

Sorry to open an issue for this but I'm trying for almost month already and with no success. I need to get the selected rows (checkbox) so I can export or do whatever I can do with all the selected rows.

Can you help me please?

kartik-v commented 9 years ago

Hope you have read the default yii guide. You may once want to do that.

This is addressed in yii\grid\CheckboxColumn... you need to write your javascript accordingly.

The selected rows may be obtained by calling the following JavaScript code:

var keys = $('#grid').yiiGridView('getSelectedRows');
// keys is an array consisting of the keys associated with the selected rows

This is also highlighted in the Krajee Grid Documentation for Checkbox Column.

dudunegrinhu commented 9 years ago

@kartik-v I already tried that but it gives me an error:

TypeError: $(...).yiiGridView is not a function

kartik-v commented 9 years ago

The error means you are using a wrong identifier for your grid. The HTML ID attribute must pertain to your gridview container.

For Dynagrid you set gridview widget properties via gridOptions - hence you can access the grid ID attribute through gridOptions['options']['id']. You may need to set a value for this and access. For example:

// widget php script
echo Dynagrid::widget([
    'options' => ['id' => 'dynagrid'], // this is dynagrid identifier
    'gridOptions' => ['options' => ['id' => 'grid']], // this is gridview identifier
    // add other settings required by DYNAGRID
]);

Then access the same via javascript.

// js script
var keys = $('#grid').yiiGridView('getSelectedRows');
// keys is an array consisting of the keys associated with the selected rows
dudunegrinhu commented 9 years ago

@kartik-v if I fix my javascript, it was because was inside the domready but now when I get the selected rows I get this error:

TypeError: data is undefined if (data.selectionColumn) {

dudunegrinhu commented 9 years ago

Sorry @kartik-v it worked now, it was a conflict name on both id's. Thanks for the clarification. I would like to make a donation to you because I'm using a lot of your components and if you have the time I would like to hire you as a consultant.

ikramadjissa commented 9 years ago

I get this error : Setting unknown property: kartik\grid\GridView::gridOptions

mohalaika commented 7 years ago

thanks a lot it's working fine but if you may how I get the full row data using the key?