locked
bind vector data from C++

    Question

  • Hi.

    I have grouped data in vector in C++ component and need to show it in grouped ListView using HTML5/JavaScript. I can use WinJS.Binding.List and then createGrouped, but because of performance and memory usage i need to do that without data copy (sometimes i need to show more than 10000 items and really don't need to have 2 instances of same data ... one in component and one in UI). Is any way to do that ? Do anybody have any example ?

    Tuesday, May 21, 2013 11:19 AM

Answers

  • Hi Petr Jurik - Ventis Media,

    I think you can see this basic code:

    <div id="groupsDiv"></div> 
    <script type="text/javascript">
        var myList = new WinJS.Binding.List([
            { name: "Marley", species: "dog" },
            { name: "Lola", species: "cat" },
            { name: "Leo", species: "dog" },
            { name: "Izzy", species: "cat" },
            { name: "Ziggy", species: "cat" },
            { name: "Ruby", species: "dog" }
        ]);
        // Create a grouped list from the item data and the grouping functions
        var myGroupedList = myList.createGrouped(getGroupKey, getGroupData, compareGroups);
        var groups = myGroupedList.groups;
        var div = document.getElementById("groupsDiv");
        var i = groups.length;
        while (--i >= 0) {
            var group = groups.getItem(i);
            div.textContent += group.data.groupDescription + " ";
            var j = group.groupSize;
            var start = group.firstItemIndexHint;
            while (--j >= 0) {
                var item = myGroupedList.getItem(start + j);
                div.textContent += item.data.name + " ";;
            }
        }
        // Sorts the groups by first letter
        function compareGroups(left, right) {
            return left.toUpperCase().charCodeAt(0) - right.toUpperCase().charCodeAt(0);
        }
        // Gets the key of the group that an item belongs to
        function getGroupKey(dataItem) {
            return dataItem.species;
        }
        // Gets the data for a group
        function getGroupData(dataItem) {
            return {
                groupDescription: dataItem.species + " group";
            };
         }

    About Bind list  you can see this document:

    msdn.microsoft.com/en-us/library/windows/apps/hh700742.aspx

    msdn.microsoft.com/en-us/magazine/jj651576.aspx

    Hope this helps!

    Wednesday, May 29, 2013 7:34 AM

All replies

  • Nobody ? Is it not possible to show vector data from C++ component without copying them ?
    Wednesday, May 22, 2013 8:53 PM
  • Hi Petr Jurik - Ventis Media,

    I think you can see this basic code:

    <div id="groupsDiv"></div> 
    <script type="text/javascript">
        var myList = new WinJS.Binding.List([
            { name: "Marley", species: "dog" },
            { name: "Lola", species: "cat" },
            { name: "Leo", species: "dog" },
            { name: "Izzy", species: "cat" },
            { name: "Ziggy", species: "cat" },
            { name: "Ruby", species: "dog" }
        ]);
        // Create a grouped list from the item data and the grouping functions
        var myGroupedList = myList.createGrouped(getGroupKey, getGroupData, compareGroups);
        var groups = myGroupedList.groups;
        var div = document.getElementById("groupsDiv");
        var i = groups.length;
        while (--i >= 0) {
            var group = groups.getItem(i);
            div.textContent += group.data.groupDescription + " ";
            var j = group.groupSize;
            var start = group.firstItemIndexHint;
            while (--j >= 0) {
                var item = myGroupedList.getItem(start + j);
                div.textContent += item.data.name + " ";;
            }
        }
        // Sorts the groups by first letter
        function compareGroups(left, right) {
            return left.toUpperCase().charCodeAt(0) - right.toUpperCase().charCodeAt(0);
        }
        // Gets the key of the group that an item belongs to
        function getGroupKey(dataItem) {
            return dataItem.species;
        }
        // Gets the data for a group
        function getGroupData(dataItem) {
            return {
                groupDescription: dataItem.species + " group";
            };
         }

    About Bind list  you can see this document:

    msdn.microsoft.com/en-us/library/windows/apps/hh700742.aspx

    msdn.microsoft.com/en-us/magazine/jj651576.aspx

    Hope this helps!

    Wednesday, May 29, 2013 7:34 AM