Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input box tr of filter may not be rendered #55

Open
yanhuixie opened this issue Aug 16, 2019 · 4 comments
Open

input box tr of filter may not be rendered #55

yanhuixie opened this issue Aug 16, 2019 · 4 comments

Comments

@yanhuixie
Copy link

yanhuixie commented Aug 16, 2019

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.

@ZAYEC77
Copy link
Contributor

ZAYEC77 commented Aug 16, 2019

Hello @yanhuixie
Thanks for your request and additional information, I'll try to resolve this issue at next week

@ZAYEC77
Copy link
Contributor

ZAYEC77 commented Aug 21, 2019

Hey @yanhuixie
Could you provide source code of calling widget because I can't reproduce this issue?
Please, check my examples here.

@yanhuixie
Copy link
Author

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'],
            ],
        ];
    }
}

@ZAYEC77
Copy link
Contributor

ZAYEC77 commented Aug 24, 2019

Hey @yanhuixie 👋
Try to remove 'scrollY' => false, property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants