gpt4 book ai didi

Magento 1.7 - 过滤网格中时间戳列的日期部分

转载 作者:行者123 更新时间:2023-12-04 23:05:09 25 4
gpt4 key购买 nike

我在网格中有以下列:

        $this->addColumn('order_date',
array(
'header'=> $this->__('Date'),
'align' =>'left',
'width' => '100px',
'index' => 'order_date',
'type' => 'date',
'filter_index' => 'orders_alias.created_at'
)
);

示例数据如下所示: http://imageshack.us/photo/my-images/502/scr028.jpg/

按日期过滤时 13 Oct 2012未找到任何行。这是有道理的,因为它是一个时间戳列。 http://imageshack.us/photo/my-images/29/scr029.jpg/

我如何才能使用 Magento 日期从/到选择器并选择 13/10/2012并显示所有行
与此日期无关?

最佳答案

这是一个仅在您尝试将值显示为日期和数据库列是日期时间或时间戳时才会出现的错误。

发生这种情况是因为日期更改为 YYYY-MM-DD HH:MM:SS 和 HH:MM:SS 是 00:00:00 的日期从和到。日期应设置为 23:59:59。

一种方法是更改​​ app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php 中的代码以支持这一点。在 setValue 函数中只需更改

编辑:第一个解决方案还需要更改 Datetime.php getValue(删除增加一天并删除一秒的代码),并且因为您不应该更改核心代码,所以第二个解决方案肯定是首选。

$value['to'] = $this->_convertDate($value['to'], $value['locale']);


$value['to'] = $this->_convertDate($value['to'], $value['locale'])->addDay(1)->subSecond(1);

由于这会更改所有过滤器的功能,因此更好的解决方案是更改您的本地代码:
$this->addColumn('order_date',
array(
'header'=> $this->__('Date'),
'align' =>'left',
'width' => '100px',
'index' => 'order_date',
'type' => 'datetime',
'filter_index' => 'orders_alias.created_at',
'frame_callback' => array( $this,'styleDate' )
)
// ...

public function styleDate( $value,$row,$column,$isExport )
{
$locale = Mage::app()->getLocale();
$date = $locale->date( $value, $locale->getDateFormat(), $locale->getLocaleCode(), false )->toString( $locale->getDateFormat() ) ;
return $date;
}

这将删除网格字段中显示的时间部分,但可以让您按照上述方式使用过滤器。

关于Magento 1.7 - 过滤网格中时间戳列的日期部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14230882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com