我只想在Silverstripe网站的CMS端显示数据库中最近的100个条目。我目前可以看到全部600个,这是不必要的。 silverstripe文档没有帮助,我无法进入他们的论坛提问。
我试图在表的ID上设置一个大于过滤器,但该过滤器不起作用。
这是我的模型管理文件
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\GridField\GridField;
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
class BonusAllocations extends ModelAdmin
{
private static $managed_models = [
'AffiliateProgram\MemberBonus'
];
private static $url_segment = 'bonus';
private static $menu_title = 'Bonuses Allocations';
public function getList()
{
$list = parent::getList();
return $list;
}
}
这是我当前的dataObject
<?php
namespace AffiliateProgram;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridField;
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
use SilverStripe\Security\Permission;
use SilverStripe\ORM\DataObject;
class MemberBonus extends DataObject
{
private static $db = [
'Amount' => 'Currency',
'Confirmed' => 'Boolean',
'Level' => 'Int',
'Percentage' => 'Int'
];
private static $has_one = [
'Member' => 'AffiliateProgram\Member',
'MemberPayment' => 'AffiliateProgram\MemberPayment',
'PaymentType' => 'AffiliateProgram\PaymentType',
'ProgramType' => 'AffiliateProgram\ProgramType'
];
private static $summary_fields = [
'Amount' => 'Amount (USD)',
'Member.Email' => 'Email',
'Level',
'MemberPayment.PaymentType.Symbol' => 'Recieved As',
'Percentage' => 'Percentage Bonus Applied',
'ProgramType.Name' => 'Program Type',
'MemberPayment.Created' => 'Payment Date',
// 'Confirmed' => 'Confirmed?',
'MemberPayment.ID' => 'Payment ID',
'ID' => 'Bonus ID'
];
public function searchableFields()
{
return [
'Member.Email' => [
'filter' => 'PartialMatchFilter',
'title' => 'Email',
'field' => TextField::class,
],
'ProgramType.Name' => [
'filter' => 'ExactMatchFilter',
'title' => 'Program',
'field' => DropdownField::create('ProgramType')
->setSource(
ProgramType::get()->map('Name','Name')
)
->setEmptyString('-- Any Program --')
],
'MemberPayment.PaymentType.Symbol' => [
'filter' => 'ExactMatchFilter',
'title' => 'Locale (Symbol)'
],
];
}
}
答案 0 :(得分:2)
在SilverStripe 4中,为了限制自定义ModelAdmin
中的列表,我们可以定义一个getList
函数并根据需要修改列表。
以下是自定义ModelAdmin
的示例,其中我们调用DataList
limit()
函数以将条目限制为最多100个项目。
use SilverStripe\Admin\ModelAdmin;
class BonusAllocations extends ModelAdmin
{
private static $managed_models = [
'AffiliateProgram\MemberBonus'
];
private static $url_segment = 'bonus';
private static $menu_title = 'Bonuses Allocations';
public function getList()
{
$list = parent::getList();
$list = $list->limit(100);
return $list;
}
}