Empty Template In ListView

Thread is closed for posting
2 posts, 0 answers
  1. YC
    YC avatar
    1 posts
    Member since:
    Jun 2012

    Posted 04 Jul 2017 Link to this post

    Hi, 

    Great job ! I like listview function using multiple template. Isn't it got empty template when items is empty? 

  2. Nikolay Iliev
    Admin
    Nikolay Iliev avatar
    351 posts

    Posted 05 Jul 2017 Link to this post

    Hi Yc Lau,

    Thank you for your interest in NativeScript!
    You can create your own templates and implement your own logic that can check if the item passed is fulfilling your criteria (e.g. empty item).
    e.g. the source array has one "empty" item (in this case no age property specified)
    this.myItems = [{ age: 34 }, { age: 25 }, {}, { age: 37 }];
    then using the itemTemplateSelector callback we can implement our custom logic
    export function selectItemTemplate(item: any, index: number, items: Array<any>) {
        return item.age ? "base" : "empty";
    }

    and from that point and item that does not have an age property will load the "empty" template
    <template key="empty">
        <StackLayout>
        <!-- your empty template follows here -->
        </StackLayout>
    </template>

    The same principle can be applied for both RadListView and ListView.

    Regards,
    Nikolay Iliev
    Progress Telerik
    Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
Back to Top