Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 24, 2013 @ 20:56
    Fuji Kusaka
    0

    TextStringArray uComponents

    Hi,

    Am knocking my head with  this dataType and i see no documentation on it either.

    Right now i created a new dataTypewith property TextStringArray using 3 rows and each having 2 columns.

    So my Html needs to render something like

    <tr>
    <td class="l">col 1</td>
    <td class="r">col 2</td>
    </tr>

    <tr>
    <td class="l">col 3</td>
    <td class="r">col 4</td>
    </tr>

    <tr>
    <td class="l">col 5</td>
    <td class="r">col 6</td>
    </tr>

    Now when i get the values from the Model this is how it renders

    <TextstringArray><values><value>Number of Employeesvalue><value>Turnover (R '000)value><value>Profit Atttributable to equity holders (Rs '000)value>values><values><value>340value><value>1,280,636value><value>9,258value>values>TextstringArray>

    This is my actual code

        @if (s.HasProperty("com") && s.GetProperty("companyFactsheet").Value.ToString() != String.Empty){

    var values = s.GetProperty("com").Value.ToString();

    <table width="255" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>@Html.Raw(values)</td>

    </tr>



    </table>
    }

    Everything gets all mess up and cant figure out how to make a new row depending on the entry row from the backend

    Any suggestion on this PLEASE ?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 24, 2013 @ 21:27
    Dirk De Grave
    1

    I ususally do a 

    var xml=XDocument.Load(s.GetProperty("companyFactsheet").Value.ToString()) and use xpath to iterate the xml.

    var descendants = xml.Descendants("values") should get you each row and

    foreach(var descendent in descendants) { var values = descendant.Descendants("value"); } should get you each col for a specific row.

     

    Cheers,

    /Dirk

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 24, 2013 @ 21:43
    Fuji Kusaka
    0

    Am gettiing error Error loading MacroEngine script.

    var xml=XDocument.Load(Model.GetProperty("com").Value.ToString());
                                                               
    var descendants = xml.Descendants("values");
    foreach(var descendent in descendants) { var values = descendant.Descendants("value"); }

    Added namespace
    @using System.Xml
    @using System.Linq
    @using System.Xml.Linq
    @using System.Collections;

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 24, 2013 @ 21:52
    Dirk De Grave
    0

    Pretty odd, i'm sure it *must* work using my approach. Bit clueless why your version wouldn't.

     

    /Dirk

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 24, 2013 @ 22:06
    Fuji Kusaka
    0

    Am i missing something here ?

    Here is the full code

    @using umbraco.MacroEngines
    @using umbraco
    @using umbraco.cms.businesslogic.datatype
    @using uComponents.DataTypes.TextstringArray
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using System.Xml
    @using System.Linq
    @using System.Xml.Linq
    @using System.Collections;



    @{
        var m = @Model;
        DynamicNode s = new DynamicNode(CurrentModel);  
       
        if(m.Where("displayFacts == true")){
            <div class="box col1 cnFactsheet">
                  <div class="cnInner">
                    <div class="cnTop"> <span class="helTh"><strong>facts</strong></span> </div>
                    <div class="cnContenu">
                    

                                @if (s.HasProperty("com") && s.GetProperty("com").Value.ToString() != String.Empty){
                                   
                                    var xml=XDocument.Load(s.GetProperty("com").Value.ToString());
                                                               
                                        var descendants = xml.Descendants("values");
                                   
                                    foreach(var descendent in descendants) { var values = descendant.Descendants("value"); }
                                   
                                }
               
                    </div>
                  </div>
                </div>
        }
       
        }
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 25, 2013 @ 08:14
    Lee Kelleher
    0

    Hi Fuji, quick question... Which version of Umbraco and uComponents?  (it will help me answer faster)

    Thanks, Lee

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 25, 2013 @ 08:33
    Fuji Kusaka
    0

    Hi Lee, working with v 4.11.8  and uComponents 5.5.0

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 25, 2013 @ 08:36
    Fuji Kusaka
    0

    Instead of using 

     var xml=XDocument.Load(s.GetProperty("com").Value.ToString()); 

    i used 

    var items = XDocument.Parse(new DynamicNode(Model.Id).GetProperty("com").Value.ToString());
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 25, 2013 @ 08:49
    Lee Kelleher
    0

    Thanks Fuji.

    In your Web.config do you have an appSettings key called "ucomponents:RazorModelBinding"? If so what's the value of it?

    I'm hoping that you'll be able to use the model-binding, as it's much easier than messing around with XML in Razor.

    Cheers, Lee

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 25, 2013 @ 08:52
    Fuji Kusaka
    0

    It is set to true .

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 25, 2013 @ 11:47
    Lee Kelleher
    100

    Hi Fuji,

    It's taken me a while to figure out the correct syntax too... mostly because I find working with the older (DynamicNode) Razor quite painful (I generally dislike dynamics anyway).

    With the Razor model-binding (for uComponents) enabled, you should be able to do this:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    <table>
        @foreach (string[] row in Model.com)
        {
            <tr>
                @foreach (var cell in row)
                {
                    <td>@cell</td>
                }
            </tr>
        }
    </table>

    Replace the "Model.com" with "Model.[whatever your property alias is]" ... this will give you a .NET type of "List<string[]>" (e.g. a list of string arrays), (but no one would ever know that because it's "dynamic" (meh!) ... then you can loop through each array (for your rows), then through each sub-array (for your cells).

    Hope this works for you.

    Cheers, Lee.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 25, 2013 @ 12:13
    Fuji Kusaka
    0

    Hi Lee,

    Thanks for the help. I tried this in the meantime but got stuck again one extra Column here. 

    Anyways yours work like a charm !!

      var items = XDocument.Parse(new DynamicNode(Model.Id).GetProperty("comp").Value.ToString());
        var rows = items.Descendants("values");
        var columns = items.Descendants("value");     
       <table>
            <tbody>    
            @if(rows.Count() > 0){
                foreach(var r in rows){
                    <tr>
                        @foreach(var cell in rows)
                        {
                            <td></td>
                        }
                    </tr>
    
                }
            }       </tbody>
           </table> 

     

      Thanks 

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 30, 2013 @ 13:07
    Fuji Kusaka
    0

    Lee what will be the appropriate way of getting the value of a column in a specific row ? 

    I will have to make a total sum of some of the entries in those cell.

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 30, 2013 @ 13:52
    Lee Kelleher
    0

    You would need to use a for loop to have the index of the current position.

    e.g.

    @for (var i = 0; i < rows.Count(); i++){
        <tr>
            @for(var j = 0; j < rows[i].Count(); j++)
            {
                <td>@rows[i][j]</td>
            }
        </tr>
    }
    

    Cheers, Lee.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 30, 2013 @ 14:30
    Fuji Kusaka
    0

    Not exactly what am trying to achieve here.

    What i need to do is to get the value of each cell so at the end i will be able to make a total sum. 

    My Html would end up something like 

    <table>
    <tr>
    <td>Some Static Txt</td>
    <td>@cell.value[1] </td>
    </tr> 
    <tr>
    <td>Some Static Txt</td>
    <td>@cell.value[2] </td>
    </tr> 
     etc
    </table>
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 30, 2013 @ 15:23
    Lee Kelleher
    0

    Do you mean something like this?

    <table>
        @foreach(var row in rows)
        {
            <tr>
                <td>First value</td>
                <td>@row[0]</td>
            </tr>
            <tr>
                <td>Second value</td>
                <td>@row[1]</td>
            </tr>
        }
    </table>
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 30, 2013 @ 20:15
    Fuji Kusaka
    0

    Silly question where did you get rows here ?

    foreach(var row in rows){}
    using @row[1] gives me an error
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 30, 2013 @ 20:39
    Fuji Kusaka
    0

    The reason i need to get the cell values seperately is because i will need those values to make some calculations in percentage to make a chart.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 31, 2013 @ 09:09
    Lee Kelleher
    0

    Sorry - I missed that out of my code snippet.

    The rows would be assigned from Model.com (replacing with whatever your property alias is).

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 31, 2013 @ 09:41
    Fuji Kusaka
    0

    using row[1] will only return the first character from the value here

     foreach(var rows in Model.propAlias){
                               foreach(var row in rows){
                                  
                                   <tr>
                                            <td>@row[1]</td>
                                     </tr>
                                      
                               }
                           }

    May be i would be best counting the rows since i only have 1 column.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 31, 2013 @ 10:20
    Lee Kelleher
    0

    You're so close... it doesn't need the inner-foreach loop. Try this:

    foreach(var row in Model.propAlias)
    {
        <tr>
            <td>@row[1]</td>
        </tr>
    }
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 31, 2013 @ 11:16
    Fuji Kusaka
    0

    This is actually the first thing i tried!!

    Not working though! :)

  • marmar 35 posts 28 karma points
    Aug 23, 2013 @ 21:26
    marmar
    0

    I am having a similar problem - the razor example does not return anything except the table tags.

    Perhaps razor binding is broken for my install?

    what should the Web.Config line for appsettings be? everytime I try to enable in the activate section of dev tab, it says its disabled -

    so ive manually added in appsettings :

    <add key="ucomponents:RazorModelBinding" value="true" />
    

    (umbraco 6.1.4, uComponents_5.5.0, IIS 7.0, .NET VersionASP.Net 4.0/4.5)

    thanks in advance for help.

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft