Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [DataObjectManager] Output To Table

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1170 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    [DataObjectManager] Output To Table Link to this post

    This might be kind of a silly question, but I am using the Data Object Manager, and wondering if there is an easy way to filter the output into a table? Instead of an ordered list, I need my Data Titles to show up 3 to a row, with an indefinite number of rows.

    Something like this:

    [Title 1] [Title 2] [Title 3]
    [Title 4] [Title 5] [Title 6]
    [Title 7] [Title 8] [Title 9]

    Displaying content is easy, but I can't figure out how I can pull these titles out 3 at a time, and wrap my <tr> tags around them.

  • UncleCheese
    Avatar
    4085 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    Is this for your frontend website? Or are you trying to change the way DOM displays in the CMS?

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    Sorry Uncle Cheese, I should've specified. This is for the front end of my website.

  • UncleCheese
    Avatar
    4085 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    So let's assume your DOM is managing the object RelatedObject.

    In RelatedObject.php:

    function Third() { return !$this->iteratorPos % 3; }

    on the template:

    <tr>
    <% control RelatedObjects %>
    <td>$Title</td>
    <% if Third %></tr><% end_if %>
    <% if Last %><% else %><tr><% end_if %>
    <% end_control %>

    Something like that oughta work.

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    Thanks Uncle Cheese. Worked like a charm. How could I go about sorting my data in alphabetical order as I pull it into the table?

  • UncleCheese
    Avatar
    4085 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    Assuming you do not have drag-and-drop sorting set up in the DOM, you can add this to RelatedObject.php

    static $default_sort = "Title ASC";

    That is, if the title field is named "Title."

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    Great Uncle Cheese, thanks.

    The sort works, except I am getting my sorting results like this

    1
    10
    19
    2

    I know that it's sorting like that because in Ascending order, 19 comes before 2. Is there a way to sort in "logical ascending order", to get the proper sort for numbers?

  • UncleCheese
    Avatar
    4085 Posts

    Re: [DataObjectManager] Output To Table Link to this post

    Make sure the field is cast as an integer.

    1170 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.