This is a migrated thread and some comments may be shown as answers.

Empty Template In ListView

1 Answer 152 Views
ListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yc
Top achievements
Rank 1
Yc asked on 04 Jul 2017, 03:22 PM

Hi, 

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

1 Answer, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 05 Jul 2017, 07:21 AM
Hi 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.
Tags
ListView
Asked by
Yc
Top achievements
Rank 1
Answers by
Nick Iliev
Telerik team
Share this question
or