Hi, I've looked everywhere I can think of, but just can't get this to work...... in my template can I reference the page from inside the dataobject (ie using $Parent or something like that)??
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.
DataObjectManager Module /
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Preview: DataObjectManager module
Hi UncleCheese,
I have had a go at adding adjustable width columns with help from simon in the irc. I can style the heading columns without a problem but for some reason can't set the width of the columns containing the Item values. I was probably trying to do it wrong - any advice? Here is the code I have implemented.
## ExamplePage.php ##
$manager->setColumnWidths(array(
'Name' => '20',
'PlanningComment' => '60',
'Date' => '20'
));
## DataObjectManager.php ##
public function setColumnWidths($Widths)
{
$this->ColumnWidths = $Widths;
}
public function Headings()
{
$headings = parent::Headings();
foreach($headings as $heading) {
$heading->IsSorted = (isset($_REQUEST['ctf'][$this->Name()]['sort'])) && ($_REQUEST['ctf'][$this->Name()]['sort'] == $heading->Name);
$Widths = $this->ColumnWidths;
$heading->Width = (isset($Widths[$heading->Name]) ? $Widths[$heading->Name] : self::$default_heading_width);
if(isset($_REQUEST['ctf'][$this->Name()]['sort_dir']))
$dir = $_REQUEST['ctf'][$this->Name()]['sort_dir'] == "ASC" ? "DESC" : "ASC";
else
$dir = "ASC";
$heading->SortDirection = $dir;
$heading->SortLink = $this->RelativeLink(array(
'sort_dir' => $heading->SortDirection,
'sort' => $heading->Name
));
}
return $headings;
}
## DataObjectManager.ss ##
<% control Headings %>
<div class="col $FirstLast" style="width: $Width%">
<div class="pad">
<a href="$SortLink">$Title
<% if IsSorted %>
<% if SortDirection = ASC %>
<img src="cms/images/bullet_arrow_up.png" alt="" />
<% else %>
<img src="cms/images/bullet_arrow_down.png" alt="" />
<% end_if %>
<% end_if %>
</a>
</div>
</div>
<% end_control %>
@howard - This was a tricky one. Undo your changes and check out the latest version to get a functional setColumnWidths() function. It can be used exactly has you built it:
$manager->setColumnWidths(array(
'Name' => 20,
'Description' => 60,
'Category' => 20
));
I believe it works best when you pass the values as integers. Make sure they add up to 100. I'll add the error checking later.
The trick to getting the individual items to draw their widths was to tap into the Fields array of the DataObjectManager_Item class. I actually ended up overloading the Fields() method inherited from TableListField to accomplish this.
Looks good so far. Please test and let me know what you think.
@tsunami - Please refer to the documentation in the SS Wiki first, and then write a detailed explanation of the problem you're having so one of us can help you out.
Yea that's brilliant, working well! I tried overloading the Fields method but somehow stuffed it up - your solution looks better :) I will keep testing, the to-do list looks good - I can't think of anything else to add at the moment.
Thanks once again.
@unclecheese - hi, sorry I know stupid questions must waste your time, but I had been through the wiki stuff and still couldn't get it to work. I've sorted it now after a bit of trial and error, and it works for my purposes but there may be a more elegant way to do it...so I'll post it ..it may help someone else.
what I had was a series of images using ImageDataObjectManager that needed to have a common identifier , so I wanted to use the parent pageID (because there are multiple child pages output on a pageholder)...the page uses jquery cycle and prettyphoto.
I ended up with:
####TreeImage.php####
class TreeImage extends DataObject
{
static $db = array (
'TreeImageCaption' => 'Text',
);
static $has_one = array (
'TreeImageFile' => 'Image',
'TreePage' => 'TreePage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('TreeImageCaption'),
new ImageField('TreeImageFile')
);
}
function theparent()
{
$parent = $this->TreePage();
return $parent;
}
}
and in TreeHolder.ss
<% control Children %>
........
<% if TreeImages %>
<div class="slider" id="cycle$ID">
<% control TreeImages %>
<a rel="prettyPhoto[$theparent.ID]" title="$TreeImageCaption" href="$TreeImageFile.URL">
<% control TreeImageFile %>
$CroppedImage(240,180)
<% end_control %>
</a>
<% end_control %>
</div>
...........
<% end_if %>
..........
<% end_control %>
final page is here
Why couldn't you just use $TreePageID?
Yes...thats the more elegant solution I was talking about :)
Uncle Cheese, can you please add this code to DataObjectManager.php.
If you are using get-functions or joined fields in the grid the SQL search string will not execute.
protected function loadSourceFilter() {
...
if(!empty($this->search)) {
$search = array();
$SNG = singleton($this->sourceClass);
foreach(parent::Headings() as $field) {
if ($SNG->hasField($field->Name))
$search[] = "UPPER($field->Name) LIKE '%".strtoupper($this->search)."%'";
}
$search_string = "(".implode(" OR ", $search).")";
}
...
}