Open yanhuixie opened 5 years ago
Hello @yanhuixie Thanks for your request and additional information, I'll try to resolve this issue at next week
Hey @yanhuixie Could you provide source code of calling widget because I can't reproduce this issue? Please, check my examples here.
Hi~ @ZAYEC77 Is this code snippet OK?
//VIEW
$renderFileNameJs = <<<EOF1
function(data, type, row, meta) { return row['fileNameWithUrl']; }
EOF1;
$renderFileSizeJs = <<<EOF2
function(data, type, row, meta) { return (data / 1024).toFixed(1) + 'KiB'; }
EOF2;
$renderYesNoJs = <<<EOF3
function(data, type, row, meta) { return data == 0 ? '' : "<span style='color:red;'>是</span>"; }
EOF3;
<?= \nullref\datatable\DataTable::widget([
'data' => $dataProvider->getModels(),
'withColumnFilter' => true,
'columns' => [
[
'data' => 'id', 'title' => Yii::t('common', 'ID'),
'filter' => false,
],
[
'data' => 'filename', 'title' => Yii::t('common', 'File Name'),
'render' => new JsExpression($renderFileNameJs),
],
[
'data' => 'size', 'title' => Yii::t('common', 'File Size'),
'filter' => false,
'render' => new JsExpression($renderFileSizeJs),
],
[
'data' => 'packed', 'title' => Yii::t('common', 'Packed'),
'filter' => false,
'render' => new JsExpression($renderYesNoJs),
],
[
'data' => 'invalid', 'title' => Yii::t('common', 'Invalid'),
'filter' => false,
'render' => new JsExpression($renderYesNoJs),
],
[
'data' => 'createdAt', 'title' => Yii::t('common', 'Create Time')
],
],
'extraColumns' => ['fileNameWithUrl'],
'serverSide' => true,
'ajax' => Url::to(['/foo/dtsviewitem',]),
'language' => new JsExpression("{'url':'$dt_i18n'}"),
'scrollX' => false,
'scrollY' => false,
"pagingType" => "full_numbers",
"order" => new JsExpression("[[ 1, 'asc' ] ]"),
"lengthMenu" => new JsExpression("[[10,20,50,100],[10,20,50,100]]"),
"tableOptions" => ["class" => "view-upl-items table table-hover table-condensed "],
"id" => "tbl_upl_items",
"globalVariable" => true
]) ?>
//CONTROLLER
class FooController extends Controller
{
public function actions(){
return [
'dtsviewitem' => [
'class' => \nullref\datatable\DataTableAction::className(),
'query' => MyAR->query(),
'extraColumns' => ['fileNameWithUrl'],
],
];
}
}
Hey @yanhuixie 👋
Try to remove 'scrollY' => false,
property.
Hi @ZAYEC77 , thanks for your awesome plugin, it helps a lot. We are using server-side mode, anything works like a charm excepts the filter. We set the withColumnFilter=>true but no filter was rendered, and we have just debugged the code, and noticed something strange. Please see https://github.com/NullRefExcep/yii2-datatables/blob/master/src/DataTable.php#L206 L206 - L216 not executed because no tr/th is rendered in the thead while L203 is executing (as Chrome debugging). Version of Chrome : 76.0.3809.100 Version of Firefox : 67.0.4 (Same thing like chrome) We have tried to register table.on('init.dt', func) and table.on('draw.dt', func) events to the datatable and copy/move L203 - L229 to the callback func, now the filter input box are rendered but still work not properly. After input something to filter, ajax request had sent but the response just not filtered, because the parameters inputted was not sent with the request. That's what we found so far, hope it will be useful to you.