search dataprovider and pagination

I am trying to implement a search function,so I copy for my needs the search code that Gii writes.

I want to ask how to set the pagination and the key for the dataprovider of the code below

$searchModel = new Buildssearch();

 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

I have this dataprovider without the search function.I found that I can set the pagination at the model,but how can we set the "totalcount"?Will dataprovider work ok without the "totalcount"

$dataProvider = new \yii\data\SqlDataProvider([

            'sql' => 'select id,code,name from mytable ',

            'totalCount' => $count,

            'key' => 'id',

            'sort' => [

                //'defaultOrder' => ['name' => SORT_DESC,],

                'attributes' => [ 'code',



            'pagination' => [

                'pageSize' => 50,



[edit] I saw an example of active data provider without "totalcount"