Silverstripe SS3数据对象在指定数据对象之后排序
好吧,这几天我都快疯了…Silverstripe SS3数据对象在指定数据对象之后排序,silverstripe,Silverstripe,好吧,这几天我都快疯了… 我有这样一个数据对象: private static $db = array( // other properties 'active' => 'Boolean', 'sort' => 'Int' // ID of another DataObject of this type, after which it is to be displayed. ); private static $has_one = array('Page' =
我有这样一个数据对象:
private static $db = array(
// other properties
'active' => 'Boolean',
'sort' => 'Int' // ID of another DataObject of this type, after which it is to be displayed.
);
private static $has_one = array('Page' => 'CustomPage');
CustomPage只是扩展了页面,并且与此DataObject有很多关系。对我来说,现在的痛苦是以正确排序的方式获取数据 编辑:排序值实际上是数据对象的ID,在该ID之后对该对象进行排序 例如:
ID sort
1 0
2 3
3 5
4 1
5 1
结果应按如下顺序排列:
ID
1
4
5
3
2
排序可以被复制,因为只要我在中间添加一些东西,我就不想麻烦更新每一项。
< P>设置<代码> DATAObjs<代码>的排序顺序是设置<代码> $Debug tStase变量:class CustomDataObject extends DataObject {
private static $db = array(
'Active' => 'Boolean',
'SortOrder' => 'Int'
);
private static $has_one = array(
'Page' => 'CustomPage'
);
private static $default_sort = 'SortOrder ASC';
}
确保执行此操作后调用?flush=all
,以清除站点缓存
此外,如果通过GridField
维护自定义DataObject
,我们可以使用模块通过拖放来控制排序顺序。下面是StackOverflow答案,详细说明了如何使用这些模块之一:
正如3dgoo所说,
$default\u sort
是你的朋友。当您的列排序
(或排序器
)不唯一时,您始终可以添加另一列来对重复项进行排序,例如
private static $default_sort = 'sort, ID ASC';
应该适用于您的情况。我可能应该提到排序值实际上是数据对象的ID,在该ID之后对该对象进行排序。所以我不能只按排序,因为那样排序不正确。例如,它会把2放在3之前,而实际上应该是相反的。