Changes
Title
unchanged
Batch Gridview data ajax send splitted in chunks displaying bootstrap Progress bar
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
AJAX,gridview,Progressbar,batch data send
Content
changed
[...]
```
The code for the controller action is the following:
/**
* Process an array of codes
* @return mixesd
* @throws BadRequestHttpException if the request is not ajax
*/[...]
The first three functions take care to show, update and hide the progress bar inside the modal window, while the `batchSend` function perform the array split and, using recursion, send the data through post ajax request, encoding the array as JSON string and calling itself until there is no more chunks to send. The last lines of code bind the click event of the `#batch_process` button checking if at least one row of Gridview has been selected. The number of elements on each array chunk can be set as the third argument of the `batchSend` function (in my case 5), you can adjust it accordingly. The first parameter is the whole array obtained by the `yiiGridView('getSelectedRows')` function.
The final result is something like this:
<img src="https://www.dijackfantasy.com/batch_send1.gif" />
...looks cool, isn't it?