Copied to clipboard

Flag this post as spam?

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


  • Naveed Ali 161 posts 426 karma points
    May 09, 2016 @ 14:53
    Naveed Ali
    0

    Alphabetical node list

    Hi All,

    I am trying to create a glossary page. This page is to have the alphabet accross the top which should be clickable to display all node items alphabeticaly.. All these items will be children of the glossary section

    I am not sure how to get them to display only when the letter is clicked..e.g If I press letter "c" all node names with first letter starting with "c" should only show and so on..

    This is my code so far..any ideas..

     @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "master.cshtml";
    
                                                var glossary = CurrentPage.Children();
                                                var glossaryItems = glossary.OrderBy("name");
                                                string letter=String.Empty;
                                                char c;
    }
    
    
        <div class="divide80"></div>
    
    
            <div class="container">
    
                <div class="row">
    
    
                    <div class="col-sm-12">
                        <div class="row">
                            <div class="col-sm-12">
                                <h4>@Umbraco.Field("title", altFieldAlias: "pageName")</h4>
                                    <p>@Umbraco.Field("bodyText")</p>
    
    
                                     <!--tab-content-->
    
                                      <!-- Nav tabs -->
    
                                      <div class="row">
                                      <div class="col-xs-12 gloss-tab">
                                  <!--tab-nav-->
    
    
    
                                        <ul class="nav nav-tabs" role="tablist">
                                            @for (c = 'A'; c <= 'Z'; ++c)
                                            {
                                                <li role="presentation" class="active"><a href="#block-a" aria-controls="home" role="tab" data-toggle="tab">@c</a></li>
    
                                            }
    
                                           </ul>
    
                                        <!--tab-panes-->
                                        <div class="tab-content">
    
    
    
    
                                           <div role="tabpanel" class="tab-pane active" id="block-a">    
                                               @foreach (var item in glossaryItems)
                                               {
                                                <div class="col-sm-12 gloss-term">
                                                    <h5>@item.Name</h5>
                                                    <p>@item.Description</p>
                                                </div>
                                               }                 
                                             @foreach (var item in glossaryItems)
                                             {
                                                 if (!letter.Equals(item.Name.Substring(0, 1)))
                                                 {
                                                     letter = item.Name.Substring(0, 1);
                                                    <div class="heading">@letter</div>
                                                 }
    
                                                <div>@item.Name</div>
                                             }
    
                                            </div>
                                            <!--/block a-->
    
                                           @*<div role="tabpanel" class="tab-pane" id="block-e">
    
                                             <div class="col-sm-12 gloss-term">
                                                <h5>Everything</h5>
                                                <p>These are the sum total of late or overdue payments for ground rent, maintenance charges or any other regular payment.</p>     
                                           </div>
    
                                           </div>*@<!--/block e-->
    
                                    </div>
                                </div>
    
                                     <!--/tab-content-->                                
    
                            </div>
                            </div>
                        </div>
    
                        <div class="divide30"></div>
                    </div>
                </div>
            </div><!--side navigation container-->
    

    Thanks

    Nav

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 07:47
    Naveed Ali
    0

    nobody else has this function on there website??

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 07:50
    Naveed Ali
    0

    this is what I am trying to acheive:

    http://index.wsu.edu/Default.aspx?al=A

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 13:19
    Naveed Ali
    0

    seems like no one has a clue on this.. after some research I have chose to use examine indexer..so that is the way to go if anyone else wants to do this..

    Thanks

    Nav

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 13:37
    Nik
    0

    Hi Naveed,

    There are a few different ways you could go about doing this, some involve Examine, some simply involve putting some filtering logic in your page view.

    I've not had to do something like this for any of the sites I've made so far but after a quick think about it you need to consider a few elements.

    1) How do you want the initial page to load? 2) Do you want each "view" to have the same url with an appended query string? 3) Do you really want to load everything when the page first loads, or just the nodes that are needed?

    You could for example, use javascript to request the contents of each "tab/letter category" from a custom controller each time a letter is clicked. This could either directly read the tree like you did in your sample code and then filter, or you could query examine in a serverside action and return a partial view or some json with the results in it.

    ------------ Edit ------------

    A quick observation from the code you posted above, you are pretty much there for a basic implementation. You just need to make your tab generation dynamic:

    Change the tabs at the top to dynamically create the link id

    bool isFirst = true;
    @for (c = 'A'; c <= 'Z'; ++c)
    {
        <li role="presentation" class="active"><a href="@string.Format("#block-{0}", c)" aria-controls="home" role="tab" data-toggle="tab">@c</a></li>
        if(isFirst )
        {
              isFirst = false;
        }
    }
    

    Then for the tabs something like this:

     @{
           isFirst = true;
     }
    @for (c = 'A'; c <= 'Z'; ++c)
    {
         <div role="tabpanel" class="tab-pane @(isFirst ? "active" : string.Emtpy)" id="@string.Format("block-{0}", c)">    
           @foreach (var item in glossaryItems.Where(gi=>gi.Name.ToLower().StartsWith(c.ToLower())
           {
                  <div class="col-sm-12 gloss-term">
                          <h5>@item.Name</h5>
                          <p>@item.Description</p>
                  </div>                     
           }
          </div>
    
        if(isFirst )
        {
              isFirst = false;
        }
    
    }
    
  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 13:43
    Naveed Ali
    0

    I have managed to get my examine index working..BUT.. when i click on other letters nothing happens..I think this is where jquery might come in?? any ideas please..

    This is what I have so far..any help is greatly appreciated:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Examine;
    @using Examine.SearchCriteria;
    @using UmbracoExamine;
    @using umbraco.NodeFactory;
    
    @{
        Layout = "master.cshtml";
    
        var glossary = CurrentPage.Children();
        var glossaryItems = glossary.OrderBy("name");
    
        string letter = String.Empty;
    
        var contentSearcher = ExamineManager.Instance.SearchProviderCollection["AzSearcher"];
        ISearchCriteria csc = contentSearcher.CreateSearchCriteria();
        IBooleanOperation query = csc.Field("__IndexType", "content").And().OrderBy(new string[] { "Name" });
    
    
    
    
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-12">
                    <h4>@Umbraco.Field("title", altFieldAlias: "pageName")</h4>
                    <p>@Umbraco.Field("bodyText")</p>
                    <!--tab-content-->
                    <!-- Nav tabs -->
                    <div class="row">
                        <div class="col-xs-12 gloss-tab">
                            <!--tab-nav-->
                            <ul class="nav nav-tabs" role="tablist">
                                <li><a href="#A-filter">A</a></li>
                                <li role="presentation"><a href="#block-b" aria-controls="profile" role="tab">B</a></li>
                                <li><a href="#B-filter">B</a></li>
                                <li><a href="#C-filter">C</a></li>
                                <li><a href="#D-filter">D</a></li>
                                <li><a href="#E-filter">E</a></li>
                                <li><a href="#F-filter">F</a></li>
                                <li><a href="#G-filter">G</a></li>
                                <li><a href="#H-filter">H</a></li>
                                <li><a href="#I-filter">I</a></li>
                                <li><a href="#J-filter">J</a></li>
                                <li><a href="#K-filter">K</a></li>
                                <li><a href="#L-filter">L</a></li>
                                <li><a href="#M-filter">M</a></li>
                                <li><a href="#N-filter">N</a></li>
                                <li><a href="#O-filter">O</a></li>
                                <li><a href="#P-filter">P</a></li>
                                <li><a href="#Q-filter">Q</a></li>
                                <li><a href="#R-filter">R</a></li>
                                <li><a href="#S-filter">S</a></li>
                                <li><a href="#T-filter">T</a></li>
                                <li><a href="#U-filter">U</a></li>
                                <li><a href="#V-filter">V</a></li>
                                <li><a href="#W-filter">W</a></li>
                                <li><a href="#X-filter">X</a></li>
                                <li><a href="#Y-filter">Y</a></li>
                                <li><a href="#Z-filter">Z</a></li>
                            </ul>
    
                            @try
                            {
                                List<SearchResult> results = contentSearcher.Search(query.Compile()).ToList();
                                foreach (var r in results)
                                {
                                    if (r.Fields.ContainsKey("pageTitle"))
                                    {
                                        r.Fields["sortValue"] = r.Fields["pageTitle"];
                                    }
                                    else
                                    {
                                        r.Fields["sortValue"] = r.Fields["nodeName"];
                                    }
    
    
                                }
    
                                for (char c = 'A'; c <= 'Z'; c++)
                                {
                                    var filter = from n in results where n.Fields["sortValue"].ToUpper().ToCharArray()[0] == c orderby n.Fields["sortValue"] select n;
    
                                    if (c == 'A')
                                    {
                                        @Html.Raw("<div role=\"tabpanel\" class=\"tab-pane\" id=\"block-\"" + c + "\">")
                                    }
                                    else
                                    {
                                        //@Html.Raw("<div class=\"tab-pane\" id=\"" + c + "-filter\" style=\"display:none\">")
                                        @Html.Raw("<div class=\"tab-pane\" id=\"" + c + "-filter\" style=\"display:none\">")
    
                                    }
                                    <div class="tab-content">
    
                                        @foreach (var l in filter)
                                        {
                                            var n = Umbraco.Content(l.Fields["__NodeId"]);
    
                                            <div class="col-sm-12 gloss-term">
                                                <h5>@n.Name</h5>
                                                <p>@n.Description</p>
                                            </div>
                                        }
                                    </div>
                                    @Html.Raw("</div>")
                                }
                            }
                            catch { }
    
                        </div>
                    </div>
    
                </div>
            </div>
        </div>
    }
    
  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 13:52
    Nik
    0

    Hi Naveed,

    I've just updated my previous reply with a possible solution (it doesn't use examine).

    If you want to go down the examine route then it could potentially be a bit more complex to implement.

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 14:18
    Naveed Ali
    0

    awesome thanks for that..

    it does not seem to like using lambda expressions when geting objects dynamically:

    @foreach (var item in glossaryItems.Where(gi=>gi.Name.ToLower().StartsWith(c.ToLower())
    

    I understand that trying to get the node name..put it to lower-case..then check it starts with same letter as my selected option..any razor way of writing this?

    Thanks for all the help

    Nav

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 14:23
    Nik
    0

    Try changing:

    var glossary = CurrentPage.Children();
    

    to

    var glossary = Model.Current.Children();
    

    This should switch it from dynamic to IPublishedContent for you.

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 14:36
    Naveed Ali
    0

    Hi,

    If I do the above I cannot use CurrentPage or Current..

    I am using MVC if that changes anything...

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 14:39
    Nik
    0

    Apologies, that should have been

    Model.Content

    not

    Model.Current

    You might have to adjust the following as well:

    var glossaryItems = glossary.OrderBy("name");
    

    to be

    var glossaryItems = glossary.OrderBy(g=>g.Name);
    
  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 14:48
    Naveed Ali
    0

    argh now it is saying that umbraco.core.models.iplublishedcontent does not take 1 argument..

    I even removed the "tolower" still the same :-(

    @foreach (var item in glossaryItems.Where(gi => gi.Name.StartsWith(c)))
    
  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 14:57
    Nik
    0

    Naveed,

    Can you paste the current code you are using that replaced this block:

    @{
         Layout = "master.cshtml";
    
         var glossary = CurrentPage.Children();
         var glossaryItems = glossary.OrderBy("name");
         string letter=String.Empty;
         char c;
    }
    

    Thanks,

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 15:00
    Naveed Ali
    0

    yup..

     Layout = "master.cshtml";
    
    var glossary = Model.Content.Children();    
    var glossaryItems = glossary.OrderBy(gi => gi.Name);
    
    char c;
    string letter = String.Empty;
    

    Thank you for helping me

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 15:03
    Nik
    0

    That's no problem. Could you paste the rest of the view, I suspect something is getting incorrectly set somewhere as my test code is working correctly.

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 15:08
    Naveed Ali
    0

    yup this is all of it.

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Examine;
    @using Examine.SearchCriteria;
    @using UmbracoExamine;
    @using umbraco.NodeFactory;
    @using IPublishedContent;
    
    @{
        Layout = "master.cshtml";
    
        var glossary = Model.Content.Children();    
        var glossaryItems = glossary.OrderBy(gi => gi.Name);
    
        char c;
        string letter = String.Empty;
    
        bool isFirst = true;
        //var contentSearcher = ExamineManager.Instance.SearchProviderCollection["AzSearcher"];
        //ISearchCriteria csc = contentSearcher.CreateSearchCriteria();
        //IBooleanOperation query = csc.Field("__IndexType", "content").And().OrderBy(new string[] { "Name" });
    
        }
    
    @*
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-12">
                    <h4>@Umbraco.Field("title", altFieldAlias: "pageName")</h4>
                    <p>@Umbraco.Field("bodyText")</p>
                    <!--tab-content-->
                    <!-- Nav tabs -->
                    <div class="row">
                        <div class="col-xs-12 gloss-tab">
                            <!--tab-nav-->
                            <ul class="nav nav-tabs" role="tablist">
                                <li><a href="#A-filter">A</a></li>
                                <li role="presentation"><a href="#block-a" aria-controls="profile" role="tab" >A</a></li>
                                <li><a href="#B-filter">B</a></li>
                                <li><a href="#C-filter">C</a></li>
                                <li><a href="#D-filter">D</a></li>
                                <li><a href="#E-filter">E</a></li>
                                <li><a href="#F-filter">F</a></li>
                                <li><a href="#G-filter">G</a></li>
                                <li><a href="#H-filter">H</a></li>
                                <li><a href="#I-filter">I</a></li>
                                <li><a href="#J-filter">J</a></li>
                                <li><a href="#K-filter">K</a></li>
                                <li><a href="#L-filter">L</a></li>
                                <li><a href="#M-filter">M</a></li>
                                <li><a href="#N-filter">N</a></li>
                                <li><a href="#O-filter">O</a></li>
                                <li><a href="#P-filter">P</a></li>
                                <li><a href="#Q-filter">Q</a></li>
                                <li><a href="#R-filter">R</a></li>
                                <li><a href="#S-filter">S</a></li>
                                <li><a href="#T-filter">T</a></li>
                                <li><a href="#U-filter">U</a></li>
                                <li><a href="#V-filter">V</a></li>
                                <li><a href="#W-filter">W</a></li>
                                <li><a href="#X-filter">X</a></li>
                                <li><a href="#Y-filter">Y</a></li>
                                <li><a href="#Z-filter">Z</a></li>
                            </ul>
    
                            @try
                            {
                                List<SearchResult> results = contentSearcher.Search(query.Compile()).ToList();
                                foreach (var r in results)
                                {
                                    if (r.Fields.ContainsKey("pageTitle"))
                                    {
                                        r.Fields["sortValue"] = r.Fields["pageTitle"];
                                    }
                                    else
                                    {
                                        r.Fields["sortValue"] = r.Fields["nodeName"];
                                    }
    
    
                                }
    
                                for (char c = 'A'; c <= 'Z'; c++)
                                {
                                    var filter = from n in results where n.Fields["sortValue"].ToUpper().ToCharArray()[0] == c orderby n.Fields["sortValue"] select n;
    
                                    if (c == 'A')
                                    {
                                        @Html.Raw("<div role=\"tabpanel\" class=\"tab-pane\" id=\"block-\"" + c + "\">")
                                    }
                                    else
                                    {
                                        //@Html.Raw("<div class=\"tab-pane\" id=\"" + c + "-filter\" style=\"display:none\">")
                                        @Html.Raw("<div class=\"tab-pane\" id=\"" + c + "-filter\" style=\"display:none\">")
    
                                    }
                                    <div class="tab-content">
    
                                        @foreach (var l in filter)
                                        {
                                            var n = Umbraco.Content(l.Fields["__NodeId"]);
                                            <div role="tabpanel" class="tab-pane active" id="@c-filter">
                                                <div class="col-sm-12 gloss-term">
                                                    <h5>@n.Name</h5>
                                                    <p>@n.Description</p>
                                                </div>
                                            </div>
                                        }
    
                                            </div>
                                    @Html.Raw("</div>")
                                }
                            }
                            catch { }
    
                        </div>
                    </div>
    
                </div>
            </div>
        </div>*@
    
    
        @for (c = 'A'; c <= 'Z'; ++c)
        {
            <li role="presentation" class="active"><a href="@string.Format("#block-{0}", c)" aria-controls="home" role="tab" data-toggle="tab">@c</a></li>
            if (isFirst)
            {
                isFirst = false;
            }
        }
    
        @{
           isFirst = true;
        }
    
        @for (c = 'A'; c <= 'Z'; ++c)
    {
            <div role="tabpanel" class="tab-pane @(isFirst ? "active" : string.Empty)" id="@string.Format("block-{0}", c)">
                @foreach (var item in glossaryItems.Where(gi => gi.Name.ToLower().StartsWith(c.ToLower())))
                {
                <div class="col-sm-12 gloss-term">
                    <h5>@item.Name</h5>
                    <p>@item.Description</p>
                </div>
                }
            </div>
    
        @if(isFirst )
        {
              isFirst = false;
        }
    
    }
    
  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 15:28
    Nik
    100
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        Layout = "master.cshtml";
    
        var glossary = Model.Content.Children();    
        var glossaryItems = glossary.OrderBy(gi => gi.Name);
    
        char c;
        string letter = String.Empty;
    
        bool isFirst = true;       
        }
    
    <ul class="nav nav-tabs" role="tablist">
       @for (c = 'A'; c <= 'Z'; ++c)
       {
          <li role="presentation" class="@(isFirst ? "active" : string.Empty)"><a href="@string.Format("#block-{0}", c)" aria-controls="home" role="tab" data-toggle="tab">@c</a></li>
          if (isFirst)
          {
              isFirst = false;
          }
       }
    </ul>
    
    
    @{
          isFirst = true;
     }
    
     <div class="tab-content">
        @for (c = 'A'; c <= 'Z'; ++c)
        {
            string curString = c.ToString();
            <div role="tabpanel" class="tab-pane @(isFirst ? "active" : string.Empty)" id="@string.Format("block-{0}", c)">
                  @foreach (var item in glossaryItems.Where(gi => gi.Name.ToLower().StartsWith(curString.ToLower())))
                 {
                      <div class="col-sm-12 gloss-term">
                           <h5>@item.Name</h5>
                           <p>@item.GetPropertyValue("description")</p>
                      </div>
                   }
            </div>
    
            if (isFirst)
            {
                 isFirst = false;
            }
    }
    </div>
    
  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    May 10, 2016 @ 15:28
    Nik
    0

    That should work for you, you might need to tweak a few little bits but that works in my test site I quickly knocked up.

  • Naveed Ali 161 posts 426 karma points
    May 10, 2016 @ 15:44
    Naveed Ali
    0

    Thank you very very much

    That works great

    You saved me lot of time :-)

    Thanks again

    Nav

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies