fedemotta / yii2-widget-datatables

DataTables widget for Yii2
MIT License
35 stars 28 forks source link

defaultOrder being ignored by DataTables #18

Open doublehops opened 7 years ago

doublehops commented 7 years ago

I have the following in the model's search method:

$dataProvider = new ActiveDataProvider([
    'query' => $query,
    'sort' => ['defaultOrder' => ['id' => 'DESC']],
]);

This works fine with GridView::widget but seems to be ignored by DataTables. Is this a known problem? I'm having trouble finding the cause.

archimodecl commented 6 years ago

In view index.php... add in clientOptions "order"=>[[column,"type"]] example: <?= DataTables::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'clientOptions' => [ // "lengthMenu"=> [[20,-1], [20,Yii::t('app',"All")]], "info"=>true, "responsive"=>true, "order"=> [[ 2, "desc" ]]