locked
listview no results display

    Question

  • Hi

    I am trying to display a text stating that no results were found, when a filter/search is done on my windows 8 app. In my html page i added the following div

    <div id="MyInteractiveTemplateNoResults" class="itemslistNoResults" data-win-control="WinJS.Binding.Template">
                    No results were returned.
    </div>

    In the js file, when there is no results from the query, i then set my listview to use the above div as my template like this:

    thisListView.itemTemplate = MyInteractiveTemplateNoResults;

    so that works sort of fine, only, it displays a list of the above div tags, so if i first searched for something, and the result was 3 items, if i run a search that doesn't return any results, the template above is displayed 3 times.

    how do i go about telling the listView/template to only display once.

    Sasha

    Wednesday, May 21, 2014 12:51 PM

Answers

  • Don't forget that if your search return  0 items to actually clear the listview's items - just setting the template will make the template apply to any existing items, hence the repeat.


    Darin R.

    • Marked as answer by Sasha_za Friday, May 23, 2014 12:36 PM
    Thursday, May 22, 2014 5:01 PM
  • hi Darin and James

    thanks for the replies, but as Darin stated that i had to clear the listview items, which is what i wasn't doing, i was just changing the template.

    I have since cleared the items, and then changed the template, so now its all working :)

    thanks again.

    Sasha

    Friday, May 23, 2014 12:36 PM

All replies

  • Hi Sasha,

    Let's think about a question, why the result is 3 items but not 4 or 5? 

    I believe that the result contain some items (probably 3) and when apply the template to the ListView, there are 3 repeated items. I would suggest you to set a breakpoint at the line where you get the result to see if the result is null or contain something.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, May 22, 2014 3:11 AM
    Moderator
  • Don't forget that if your search return  0 items to actually clear the listview's items - just setting the template will make the template apply to any existing items, hence the repeat.


    Darin R.

    • Marked as answer by Sasha_za Friday, May 23, 2014 12:36 PM
    Thursday, May 22, 2014 5:01 PM
  • hi Darin and James

    thanks for the replies, but as Darin stated that i had to clear the listview items, which is what i wasn't doing, i was just changing the template.

    I have since cleared the items, and then changed the template, so now its all working :)

    thanks again.

    Sasha

    Friday, May 23, 2014 12:36 PM