微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

点击分页时,Yii2停止页面重新加载

如何解决点击分页时,Yii2停止页面重新加载

我有一个index页面,在其中基于选择调用一些视图。另外,我有一个在每个发送的请求上提交的表单。

<section class="container-fluid">
    <div class="Box">
        <div class="Box-body">
            <form action="index" method="post" >
                <select required id="s" name="dtype" class="dropdown"
                        style="float: left; text-align: left;width: 20%; margin: 10px;">
                    <option value="400">Select Data Type</option>
                    <option value="401"<?PHP if(isset($_POST['dtype']) && $_POST['dtype'] == '401')
                        echo 'selected= "selected"';
                    ?>>Current</option>
                    <option value="402"<?PHP if(isset($_POST['dtype']) && $_POST['dtype'] == '402')
                        echo 'selected= "selected"';
                    ?>>Voltage</option>
                    <option value="403"<?PHP if(isset($_POST['dtype']) && $_POST['dtype'] == '403')
                        echo 'selected= "selected"';
                    ?>>kWh</option>
                </select>
                <input style="float: left; text-align: left; margin: 10px; width: 15%" type="text" id="name" name="msn" required
                       minlength="4" maxlength="15" size="15" placeholder="MSN"
                value="<?PHP echo isset($_POST['msn']) ? htmlspecialchars($_POST['msn'],ENT_QUOTES) : ''; ?>">



                    <?PHP

                    echo DateTimePicker::widget([
                        'name' => 'datetime_10','id'=>'start','value' => Yii::$app->request->post('datetime_10',null),'options' => [
                                'placeholder' => 'Start','autocomplete' => 'off','required' =>true,],'convertFormat' => false,'pluginoptions' => [
                            'format' => 'yyyy-mm-dd hh:i:ss',//'startDate' => '01-Mar-2014 12:00 AM','todayHighlight' => true,'autoclose' => true,]
                    ]);
                  echo  DateTimePicker::widget([
                        'name' => 'datetime_11','id'=>'end','value' => Yii::$app->request->post('datetime_11','options' => [
                            'placeholder' => 'End',]
                    ]);
                    ?>
                <input type="submit" value="Query" id="btnSubmit" class="btn btn-success pull-right" style="margin: 5px" />

            </form>

        </div>
    </div>
</section>

    <section class="content">

        <div class="Box">
            <div class="Box-body">

    <?PHP // echo $this->render('_search',['model' => $searchModel]); ?>


    <?PHP
    if($type == '401')//current
    {

        $columns = [
            [
                    'class' => 'yii\grid\SerialColumn','Device_ID','Customer_ID','MSN','Current_Phase_1','Current_Phase_2','Current_Phase_3','Data_Date_Time',];
        echo $this->render('_currentChart',[
            'dataProvider' => $dataProvider,]) ;


    }else if($type == '402')//voltages
    {
        $columns = [
            [
                    'class' => 'yii\grid\SerialColumn','Voltage_Phase_1','Voltage_Phase_2','Voltage_Phase_3',];
        echo $this->render('_voltageChart',]) ;
    }
    else if($type == "403")
    {
        $columns = [
            [
                    'class' => 'yii\grid\SerialColumn','kWh_Total',];
        echo $this->render('_kwhChart',]) ;
    }
    else if($type == "404")
    {
        $columns = [
            ['class' => 'yii\grid\SerialColumn'],'Total_Power','Data_Time',];
        echo $this->render('_totalChart',]) ;
    }
    else
    {
        $columns = [
            ['class' => 'yii\grid\SerialColumn'],'device_id','cust_id','msn','kwh_t','voltage_p1','voltage_p2','voltage_p3','current_p1','current_p2','current_p3','data_date_time',];

    }
    ?>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,//'filterModel' => $searchModel,'columns' => $columns
    ]);
    ?>
            </div>
        </div>
    </section>

当前图表

<?PHP
 
 $dataPointsC1 = array();

 $dataPointsC2 = array();

 $dataPointsC3 = array();
 $model = $dataProvider->getModels();
 foreach ($model as $row){

 // pushing for voltages
 array_push($dataPointsC1,array("label"=>$row['Data_Date_Time'],"y"=>$row['Current_Phase_1']));
 array_push($dataPointsC2,"y"=>$row['Current_Phase_2']));
 array_push($dataPointsC3,"y"=>$row['Current_Phase_3']));
 }

 ?>
            <div id="chartContainer1" style="width: 100%; height: 300px;display: inline-block;"> 
 </div>

<script>
var chart1 = new CanvasJS.Chart("chartContainer1",{
    exportEnabled: true,animationEnabled: true,zoomEnabled: true,theme: "light1",title:{
        text: "Current"
    },legend:{
        cursor: "pointer",verticalAlign: "bottom",horizontalAlign: "center",itemclick: toggleDataSeries
    },data: [
        {
            type: "line",//lineColor:"yellow",// legendMarkerColor: "yellow",name: "Current(Phase-1)",indexLabel: "{y}",//yValueFormatString: "V1#0.##",showInLegend: true,dataPoints: <?PHP echo json_encode($dataPointsC1,JSON_NUMERIC_CHECK); ?>
        },{
            type: "line",// lineColor:"orange",// legendMarkerColor: "orange",name: "Current(Phase-2)",//yValueFormatString: "V2#0.##",dataPoints: <?PHP echo json_encode($dataPointsC2,// lineColor:"purple",//  legendMarkerColor: "purple",name: "Current(Phase-3)",//yValueFormatString: "V3#0.##",dataPoints: <?PHP echo json_encode($dataPointsC3,JSON_NUMERIC_CHECK); ?>
        }
    ]

});
chart1.render();


function toggleDataSeries(e){
    e.dataSeries.visible = !(typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible);
    chart1.render();

}


</script>

在任何过滤器之前屏幕

enter image description here

过滤后屏幕

enter image description here

页面也带有分页。当我单击分页时,整个页面将重新加载并设置为原始状态。

我该如何管理?

解决方法

使用pjax https://www.yiiframework.com/doc/api/2.0/yii-widgets-pjax 在您的索引视图中

init

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。