Is there a way to select all items across pages?
Closed this issue · 2 comments
Hi, thanks for the widget!
Is there any elegant way to show "select all [x] items on all pages" control somewhere near checkbox in thead?
Hello!
You should create your own component extended from the yii\grid\CheckboxColumn
class and modify in it the renderHeaderCellContent()
method. The improved method must render one more checkbox. After you need to edit url attribute of a select option in a view (e.g. to Url::toRoute(['delete-multiple', 'force-check-all' => 0])
) and add following JS code:
$this->registerJs("$('input[name=\"force_selection_all\"]').change(function() {
value = this.checked ? 1 : 0;
$('#bulk-actions option').each(function() {
var url = $(this).attr('url');
if (url) {
$(this).attr('url', url.replace(/force-check-all=(\d+)/, 'force-check-all=' + value));
}
});
});");
where force_selection_all
is a name attribute of the new checkbox. Now, in the controller action depending on value of the force-check-all
GET parameter you can delete all rows.
But I not recommend manipulate items from hidden pages. I think the best way is to add function to dynamically change the page size of a grid.
Closed for the lack of discussion.