Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason Mackay 98 posts 149 karma points
    Mar 12, 2013 @ 19:18
    Jason Mackay
    0

    uComponents Data Type Grid - Razor Syntax

    Hey,

    Was wondering if anyone colud help me with this problem, I reckon I must be close to a solution, but here goes - I have set up a new Data Type using the uComponent: DataType Grid. Which looks like this:

    I've then put this on to a page and put in some dummy code, I've then used the razor code from the blog post: http://ucomponents.org/data-types/datatype-grid/razor-samples/

    So my Razor code looks like:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    <h3>Show raw data</h3>
    <p>@Model.DataTypeGrid</p>
    
    <h3>List all rows and cells</h3>
    <table cellspacing="0" cellpadding="0">
        <tr>
            <th>Row ID</th>
            <th>Row SortOrder</th>
            <th>Row Cells</th>
        </tr>
        @foreach(var row in Model.DataTypeGrid) {
            <tr>
                <th>@row.Id</th>
                <th>@row.SortOrder</th>
                <td>
                    <table cellspacing="0" cellpadding="0">
                        <tr>
                            <th>Item</th>
                            <th>Price</th>
                            <th>Description</th>
                        </tr>
                        @foreach(var cell in row) {
                            <tr>
                                <td>@cell.menu</td>
                                <td>@cell.price</td>
                                <td>@cell.desc</td>>
                            </tr>
                        }
                    </table>
                </td>
            </tr>
        }
    </table>

    This gives me the table names but none of the information inside the cells, I reckon I am doing something stupid and cant see it. 
    Anyone else know what the problem could be?

    Thanks in advance.

    Jason

  • Rich Green 2246 posts 4008 karma points
    Mar 12, 2013 @ 20:28
    Rich Green
    0

    Hey Jason,

    Does looking at the /App_Data/umbraco.config help?

    Rich

  • gary 385 posts 916 karma points
    Mar 13, 2013 @ 00:18
    gary
    0

    Hi Jason

    Could it be 

    <td>@cell.Menu</td>
                                                           
    <td>@cell.Price</td>
                                                            <td>@cell.Desc</
    td>>

    That would be normal in Umbraco and does seem to be the same from the link you posted.

    Other than that, have no idea: G

     

     

     

     

  • Francisco 21 posts 72 karma points
    Mar 13, 2013 @ 00:29
    Francisco
    0

    Have you filled your grid with some data?

    I have been using DataType-grid here quite a lot, and it works fine.

  • gary 385 posts 916 karma points
    Mar 13, 2013 @ 00:38
    gary
    0

    Hi Francisco

    I am kind of assuming that you are using the same version of Umbraco as you have when you used this prefiously, and that this was not working.

    As I looked at it, the property names have lowercase first letters, I think they should be capital letters, ie not @cell.menu, but @cell.Menu. I checked via the link you posted and capital letters are used there, so think it should be the same.

    I have not used data-type grid, but read you post to try to see if I could learn something.

  • Jason Mackay 98 posts 149 karma points
    Mar 13, 2013 @ 10:14
    Jason Mackay
    0

    Hey guys, thanks for your help, but the capatalisation didnt work! 
    @Rich - Umbraco.config would only show me errors would it not, there arent any errors for the script it just doesnt seem to be showing. 

    @Gary - tried with the capitals and nothing seemed to change.

    @Francisco - there is data there I have two rows of data:

    This didnt seem to work, it must be something small just cant seem to get it!

  • Rich Green 2246 posts 4008 karma points
    Mar 13, 2013 @ 10:16
    Rich Green
    0

    Hey Jason,

    It might have be quicker to look at the umbraco.config file :)

    Rich

  • Jason Mackay 98 posts 149 karma points
    Mar 13, 2013 @ 10:21
    Jason Mackay
    0

    Hey Rich,

    My XML for this looks like: 

     <FoodPage id="1096" parentID="1050" level="2" writerID="0" creatorID="0" nodeType="1047" template="1093" sortOrder="5" createDate="2013-03-12T18:03:49" updateDate="2013-03-13T09:19:59" nodeName="Food2" urlName="food2" writerName="admin" creatorName="admin" path="-1,1050,1096" isDoc="">
          <test>
            <items>
              <item id="1">
                <menu nodeName="Menu" nodeType="-88">Home Made Soup</menu>
                <price nodeName="Price" nodeType="-88">£3.30</price>
                <desc nodeName="Desc" nodeType="-89">Served with crusty bread. </desc>
              </item>
              <item id="2">
                <menu nodeName="Menu" nodeType="-88">Cod Goujons</menu>
                <price nodeName="Price" nodeType="-88">£3.30</price>
                <desc nodeName="Desc" nodeType="-89">Strips of cod encased in a golden crumb, served with salad.</desc>
              </item>
            </items>
          </test>
        </FoodPage>

    Do you see anything that could be wrong with this?

  • Rich Green 2246 posts 4008 karma points
    Mar 13, 2013 @ 10:28
    Rich Green
    0

    Hey Jason,

    What version of Data Type grid are you using?

    Rich

  • Jason Mackay 98 posts 149 karma points
    Mar 13, 2013 @ 10:29
    Jason Mackay
    0

    Right think I might be a step closer.

    Instead of @Model.DataTypeGrid - I have called mine 'Test' so I have placed in @Model.test. This then throws me up the error :

    Error loading Razor Script Menu.cshtml
    'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'menu' 

    I have tried Menu and menu but still nothing, anyone else got a thought about this? 

  • gary 385 posts 916 karma points
    Mar 13, 2013 @ 10:32
    gary
    0

    Hi Jason

    Try hitting save and publish again on your docType then save and publish again, this may be Version specific, but I have had this before, when clearly it does exist but is not being recognized.

    G

  • Jason Mackay 98 posts 149 karma points
    Mar 13, 2013 @ 10:50
    Jason Mackay
    0

    Had uComponents 3.2 - I think. Tried uninstalling and putting v5.4.0 and now got another error within Umbraco. Deleted the Datatype and readded a new one and cant open the page in Umbraco now.

    Completely lost now!

     

  • Stephen 47 posts 270 karma points
    Mar 13, 2013 @ 10:59
    Stephen
    0

    Not sure where you are with this, but when I pulled out data I did it along the lines of this:

     DynamicXml capacitiesXml = Model.Content.GetPropertyValue<DynamicXml>("capacities");
    
        var capacities = capacitiesXml.BaseElement.Elements("item");
    
        foreach (XElement capacity in capacities)
        {
            <li>
                <label>capacity.Element("name").Value</label>
            </li>
        }
    
    

     

  • Stephen 47 posts 270 karma points
    Mar 13, 2013 @ 11:11
    Stephen
    100

    Actually looking at your code, if you replace with @cell.Value you should get the value of each property out (and cell.Alias to get the alias etc).  

    But I'm guessing if you want a table of all the results you need something like this?

     

    <h3>List all rows and cells</h3>
    <table cellspacing="0" cellpadding="0">
            <tr>
                    <th>Menu</
    th>
                   
    <th>Price</th>
                    <th>Description</
    th>
           
    </tr>
            @foreach(var row in Model.DataTypeGrid) {
                    <tr>
                            <td>@row.Menu</td>
    <td>@row.Price</td><td>@row.Desc</td>
     
                    </tr>
           
    }
    </table>

     

  • Jason Mackay 98 posts 149 karma points
    Mar 13, 2013 @ 11:59
    Jason Mackay
    0

    Mr Rogers,

    I am almost there using :

    <h3>List all rows and cells</h3>
        <table cellspacing="0" cellpadding="0">        
        <tr>                
        <th>Menu</th>                
        <th>Price</th>                
        <th>Description</th>        
        </tr>        
        @foreach(var row in Model.test) 
        {                
            <tr>                        
                <td>@row.menu</td>
                @*<td>@row.Price</td>
                <td>@row.Desc</td>  *@                
            </tr>        
        }
    </table>

     I've got it pumping out 'umbraco.MacroEngines.DynamicXml' how do I then get the Value of this. tried @row.menu.Value. Not sure of the correct syntax. Any ideas?

  • Stephen 47 posts 270 karma points
    Mar 13, 2013 @ 12:09
    Stephen
    0

    Ah you want to be looking at the "up until 5.4.0" version of the code and use

    @row.menu.InnerText

     

     

  • Jason Mackay 98 posts 149 karma points
    Mar 13, 2013 @ 12:14
    Jason Mackay
    0

    You sir are a beautiful beautiful man!

    Works a treat.

    Yeah had to revert back to using one before 5.4.0 as it buggered up and I couldnt be bothered messing around with Dll's!

    Thanks for everyones help - the final code I needed (if this helps anyone) is:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    <h3>Show raw data</h3>
    <p>@Model.test</p>
    
    
    <h3>List all rows and cells</h3>
        <table cellspacing="0" cellpadding="0">        
        <tr>                
        <th>Menu</th>                
        <th>Price</th>                
        <th>Description</th>        
        </tr>        
        @foreach(var row in Model.test) 
        {                
            <tr>                        
                <td>@row.menu.InnerText</td>
                <td>@row.Price.InnerText</td>
                <td>@row.Desc.InnerText</td>              
            </tr>        
        }
    </table>
  • Craig100 1136 posts 2523 karma points c-trib
    Jun 22, 2013 @ 01:02
    Craig100
    0

    Similar problem but in an MVC site Umb V6.1.1 uComp V5.4. Can't get the syntax to access uComponents DataTypeGrid.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <section class="well"> <div class="row-fluid"> <div class="span8"> <h3>@Umbraco.Field("sectionTitle")</h3> <ul class="unstyled"> @{var grid = Model.Content.GetProperty("assocLinks");} @foreach(var row in grid){ <li><a href="@row.linkAddress">@row.linkText &DoubleRightArrow;</a></li> } </ul> </div> </section> 

    The "foreach" gets a wavy line in VS2012 saying "foreach statement cannot operate on vairables of type 'Umbraco.Core.Models.IPublishedContentProperty' because it does not contain a public definition for 'GetEnumerator'.

    How do you get the data out in Razor?

    Any help would be appreciated.

    Cheers,

    Craig

  • Kalpesh Dave 6 posts 26 karma points
    Jan 03, 2015 @ 11:41
    Kalpesh Dave
    0

    Hello Friends,

    I am totaly new in Umbraco, and I have the fix requirement to work with ucomponents DataType Grid. That was I did good, but now I struck up when I am going to retrived data from the cell (i.e. textstring) through javascript.. Please help me to get out of that.. I do not want to use Razor ..

    Thanks.

     

Please Sign in or register to post replies

Write your reply to:

Draft