A DataProvider is not a set of data, but a PHP object that provides a set of data. It is usually used by some data widget like GridView and ListView to create a grid or list in HTML format. All of this happens in server side.
If you want to update a grid by ajax, you have to return the updated html data of the grid as a response.
BTW, I would like to recommend you revisit Gii’s CRUD generator before you try to do it by yourself. You just have to check Enable Pjax.
actionIndex() remains the same even when you have enabled Pjax. It will return the same content as a response for Pjax request. The javascript provided by Yii will use only the content enveloped in Pjax widget to update the DOM in the client browser … yes, you don’t need to write a javascript for Pjax by yourself. Pjax widget will automatically do it.
And if you want to optimize your code a little, you can modify your actionIndex like the following.
public function actionIndex()
{
$searchModel = new SlipSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (Yii::$app->request->isPjax) {
return $this->renderPartial('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} else {
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
Now we are returning the output HTML without the wrapping layout using renderPartial for Pjax request.