M
martin.pichler
Hi,
I am trying to sort a repeating table with the help of JScript. I found
an example in an demoform that came with Infopath.
I am using this code, but I could not figure out what the function
expects as fnCompare.
Can anyone shed some light please? I always get an error at this line
rgItems.sort(fnCompare);
Thanks in advance, Martin
function sort(xpathParent, xpathChildren, fnCompare)
{
// Retrieve the parent node; all the children will be sorted.
var xmlOrigParent = getNode(xpathParent)
var xmlItems = xmlOrigParent.selectNodes(xpathChildren);
if (1 < count(xmlItems))
{
// Store the (pointers to) items in an array for faster access.
rgItems = new Array();
while (xmlItem = xmlItems.nextNode())
rgItems.push(xmlItem);
// Sort the array (the XML does not change).
-------> rgItems.sort(fnCompare);
// Now that the array is sorted the DOM should be updated.
var xmlSortParent = xmlOrigParent.cloneNode(true);
var xmlClones = xmlSortParent.selectNodes(xpathChildren);
xmlClones.removeAll();
// Update the nodelist, each item is moved only once.
// (each change is causing several notifications to be fired.)
for (var i=0; i<rgItems.length; i++)
xmlSortParent.appendChild(rgItems.cloneNode(true));
xmlOrigParent.parentNode.replaceChild(xmlSortParent, xmlOrigParent);
}
}
I am trying to sort a repeating table with the help of JScript. I found
an example in an demoform that came with Infopath.
I am using this code, but I could not figure out what the function
expects as fnCompare.
Can anyone shed some light please? I always get an error at this line
rgItems.sort(fnCompare);
Thanks in advance, Martin
function sort(xpathParent, xpathChildren, fnCompare)
{
// Retrieve the parent node; all the children will be sorted.
var xmlOrigParent = getNode(xpathParent)
var xmlItems = xmlOrigParent.selectNodes(xpathChildren);
if (1 < count(xmlItems))
{
// Store the (pointers to) items in an array for faster access.
rgItems = new Array();
while (xmlItem = xmlItems.nextNode())
rgItems.push(xmlItem);
// Sort the array (the XML does not change).
-------> rgItems.sort(fnCompare);
// Now that the array is sorted the DOM should be updated.
var xmlSortParent = xmlOrigParent.cloneNode(true);
var xmlClones = xmlSortParent.selectNodes(xpathChildren);
xmlClones.removeAll();
// Update the nodelist, each item is moved only once.
// (each change is causing several notifications to be fired.)
for (var i=0; i<rgItems.length; i++)
xmlSortParent.appendChild(rgItems.cloneNode(true));
xmlOrigParent.parentNode.replaceChild(xmlSortParent, xmlOrigParent);
}
}