Yii2:为gridview添加数据选择器

时间:2019-02-11 13:02:26

标签: yii2 yii2-advanced-app yii2-basic-app yii2-model

我有相关表中某些数据的输出代码。但是我还有任务要按日期添加2个搜索字段。

应该有2个字段<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <label for="form_name">Title</label> <select class="bootstrap-select"> <option value="1" selected="selected">Feature 1</option> <option value="2">Feature 2</option> <option value="3">Feature 3</option> <option value="4">Feature 4</option> </select> <div> <p id="1">Text1</p> </div> <div> <p id="2">Text2</p> </div> <div> <p id="3">Text3</p> </div> <div> <p id="4">Text4</p> </div>created_at选择可以过滤掉多余数据的日期

我的控制器:

end_at

并查看:

{
    $dateNowMinusMonth = new \DateTime('-1 month');
    $payed = OrderPayment::find()->where(['status' => OrderPayment::STATUS_PAYED])
        ->andWhere(['>=', 'created_at', $dateNowMinusMonth->format('Y-m-d H:i:s')])
        ->all();
    $orderIds = ArrayHelper::getColumn($payed, 'order_id');
    $elements = [];
    if ($orders = Order::find()->where(['id' => $orderIds])->all()) {
        foreach ($orders as $order) {
            foreach ($order->elements as $element) {
                $product = $element->product;
                if (array_key_exists($product->id, $elements)) {
                    $elements[$product->id]['count'] += 1;
                } else {
                    $elements[$product->id] = [
                        'name' => $product->name,
                        'barcode' => $product->barcode,
                        'count' => 0,
                        'amount' => $product->storitem->amount,
                        'item_cost' => $product->purchase->item_cost,
                        'price' => $product->price,
                    ];
                }
            }
        }
    }
    $dataProvider = new ArrayDataProvider([
        'allModels' => $elements,
        'sort' => [
            'defaultOrder' => ['count' => SORT_DESC],
            'attributes' => ['name', 'count', 'barcode', 'amount', 'item_cost', 'price']
        ],
        'pagination' => [
            'pageSize' => 15,
        ],
    ]);
    return $this->render('Reporat', [
        'dataProvider' => $dataProvider,
    ]);
}

请帮助我添加2个字段,通过它们我可以按创建日期和结束日期过滤显示的数据。

0 个答案:

没有答案