Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Basic Gridfield + Sortable + Pagination Example SilverStripe3 ss3


Go to End


4 Posts   2296 Views

Avatar
DesignerX.com.au

Community Member, 107 Posts

10 August 2012 at 9:01pm

Edited: 10/08/2012 9:02pm

Hi, I see many question about using the GrildField & sortable module , so here is an example of how to get the working (tesed on SS3.0.1):
download the files & see the example , I provided a basic template file too so you can give it a quick drive test ;)

Note that you will need to download the Sortable Module from : https://github.com/UndefinedOffset/SortableGridField

Attached Files
Avatar
DesignerX.com.au

Community Member, 107 Posts

31 August 2012 at 2:15am

Hi: for auto sorting of object when adding new items, you need to add this code to your Object , for example:
if Gallery has_many GalleryImages , add this code on the GalleryImages class :

function onBeforeWrite() {
parent::onBeforeWrite();
if (!$this->SortID) {
$this->SortID = $this->getNextSortID();
}
}

function getNextSortID() {
$getDataList = $this->SGallery()->Images();
if (!$getDataList || $getDataList->Count() == 0) {
return NULL;
} else {
return $getDataList->first()->SortID + 1;
}
}
PM me on the IRC if you have any questions

Avatar
UndefinedOffset

Community Member, 30 Posts

31 August 2012 at 2:36am

Shouldn't have to manually auto increment the number SortableGridField detects this the next time the GridField is displayed. It will not update if you're still in the Edit/Add Form.

Avatar
DesignerX.com.au

Community Member, 107 Posts

5 September 2012 at 12:35am

yep, its fixed now.. I guess I had an old copy of the module . as of 4/9/12 the module will take care of incrementing :D