使用pjax重新加载Yii2 Datatable

时间:2019-02-14 03:22:36

标签: php datatables yii2 pjax

我有这个问题。我正在使用yii2。我正在使用数据表来显示我的内容。一切都好。但是当我使用Pjax重新加载表时。一些div会丢失。这是屏幕截图:

enter image description here

这是在提交pjax之前。

enter image description here

提交后的这个

有人知道如何通过pjax重新加载div吗? 谢谢。

这是我提交时的_form代码:

$script = <<< JS

$('form#{$model->formName()}').on('beforeSubmit', function(e)
{
    var \$form = $(this);
    $.post(
    \$form.attr('action'),
    \$form.serialize(),
    )
    .done(function(result){
       if (result == 1)
       {
        $(\$form).trigger('reset');
        $.pjax.reload({
            container: '#w0',
            timeout: false
        });
    } else {
        $('#message').html(result);
    }
}).fail(function()
{
    console.log('server error');
});
    return false;
});

JS;
$this->registerJs($script);

1 个答案:

答案 0 :(得分:2)

当您将 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:text="Hello" android:background="@color/colorPrimary" android:layout_width="wrap_content" android:layout_height="40dp"/> <TextView android:text="world" android:background="@color/colorAccent" android:layout_width="wrap_content" android:layout_height="40dp"/> </LinearLayout> 用于Pjax的搜索过滤器并重新加载DataTable时,将从主容器中删除DataTable插件的初始化。

您应该使用Pjax插件提供的Events,对于当前情况,您可以使用

  

Pjax:总是在ajax之后触发,无论   结果。

因此您可以绑定事件以将pjax:complete脚本重新加载到如下所示的容器上。

DataTable

希望有帮助。