selecting current - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

selecting current

Last post 01-24-2007 08:24 PM by oz213. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 01-17-2007 04:43 PM

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11

    selecting current

    I have a form that is a job tracking system. It has Job Category with a Job list in it. You can add jobs to the category or add a completely new category. I then need to be able to sort the job list by jobs completed. I have it working in the first category but when you add a second job category and try to sort it, they all only sort the first category.

    How to a tell the for to sort the current category you are in and not the first?
  • 01-17-2007 05:59 PM In reply to

    Hi Oz213 and welcome to our forum,
    Sounds like an xpath issue involving current(). This is one of the most frequently discussed topics. There are many posts and several HowTos from Greg on it. If this is an xpath issue, please search for "current preceding-sibling". If this is not an xpath issue, please reply with more details (i.e. code), so we can have a look.
    Patrick Halstead
    Project Manager at Qdabra
  • 01-17-2007 06:44 PM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    Thanks Patrick for the help and the welcome.

    I will search for "current preceding-sibling" and see what I can find. If that doesn't do it, I'll be back with more code for help.
  • 01-17-2007 07:02 PM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    OK. I looked around and it still doesn't make sense. Maybe because I am new to Infopath. Here is the code.


    //////////////////////////////////

    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-06T19:05:06" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
    //</namespacesDefinition>

    // Counter used to create a unique key for each Asset.
    var g_iCounter = 1;

    // The relative XPath from <asset> to the element used for comparison.
    // It has value only when the sort is in progress.
    var g_xpathSortBy = "";

    // The nodes of double type should be compared as numbers, not as text.
    var g_parseAsNumber = false;


    /*==============================================================================
    Private functions
    ==============================================================================*/

    function getValue(xmlNode)
    {
    if (g_parseAsNumber && !isInvalidOrEmpty(xmlNode))
    {
    var value = convertXMLNumberToJScript(xmlNode.nodeTypedValue);

    if (!isNaN(value))
    return value;
    }

    return xmlNode.text.toLowerCase();
    }

    function compareAssets(xmlAssetLeft, xmlAssetRight)
    {
    var xmlLeft = xmlAssetLeft.selectSingleNode(g_xpathSortBy);
    var xmlRight = xmlAssetRight.selectSingleNode(g_xpathSortBy);

    var valueLeft = getValue(xmlLeft);
    var valueRight = getValue(xmlRight);

    if ((valueLeft < valueRight) || (typeof(valueLeft) == "number" && typeof(valueRight) == "string"))
    return -1;
    else if ((valueLeft > valueRight) || (typeof(valueLeft) == "string" && typeof(valueRight) == "number"))
    return 1;
    else
    return 0;
    }

    /* =============================================================================
    Node value operations
    ============================================================================= */

    /*------------------------------------------------------------------------------
    isInvalidOrEmpty()
    ------------------------------------------------------------------------------*/
    function isInvalidOrEmpty(xmlNode)
    {
    // If there is no value, ignore it.
    if (!xmlNode || !xmlNode.text)
    return true;

    // The caller can pass additional error types as optional arguments.
    var aErrorTypes = new Array;
    if (arguments.length > 1)
    {
    for (var i=1; i<arguments.length; i++)
    aErrorTypes.push(arguments);
    }
    else
    {
    aErrorTypes.push("SCHEMA_VALIDATION");
    }

    // If there is a validation error related to this node,
    // then the node is invalid.
    for (var i=0; i<XDocument.Errors.Count; i++)
    {
    var oError = XDocument.Errors(i);

    if (xmlNode == oError.Node)
    {
    for (var j in aErrorTypes)
    {
    if (oError.Type == aErrorTypes[j])
    return true;
    }
    }
    }

    // Is valid (no error was found).
    return false;
    }

    /*------------------------------------------------------------------------------
    getNodeValue()
    ------------------------------------------------------------------------------*/
    function getNodeValue(xpath, defaultValue)
    {
    var xmlNode = getNode(xpath);

    if (isInvalidOrEmpty(xmlNode))
    return (arguments.length > 1) ? defaultValue : "";
    else
    return xmlNode.text;
    }

    /*------------------------------------------------------------------------------
    getNode()
    ------------------------------------------------------------------------------*/
    function getNode(xpath)
    {
    // Both XML node and absolute XPath are allowed.
    if (typeof(xpath) == "string")
    return XDocument.DOM.selectSingleNode(xpath);
    else
    return xpath;
    }

    /*------------------------------------------------------------------------------
    getNodeList()
    ------------------------------------------------------------------------------*/
    function getNodeList(xpath)
    {
    // Both XML node and absolute XPath are allowed.
    if (typeof(xpath) == "string")
    return XDocument.DOM.selectNodes(xpath);
    else
    return xpath;
    }

    /*------------------------------------------------------------------------------
    count()
    ------------------------------------------------------------------------------*/
    function count(xpath)
    {
    var xmlNodeList = getNodeList(xpath);

    if (xmlNodeList)
    return xmlNodeList.length;
    else
    return -1;
    }

    /*------------------------------------------------------------------------------
    sort()
    ------------------------------------------------------------------------------*/
    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);
    }
    }
    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function btnSortChecked::OnClick(eventObj)
    {
    // Avoid side effects when DOM is read only.
    if (XDocument.IsDOMReadOnly)
    return;

    // It is used by comparison function, and to flag sort in progress.
    // The generation of unique keys is suppressed while sort is in progress.
    g_xpathSortBy = "my:Completed";

    if (!g_xpathSortBy)
    return;

    sort("/my:Job_Tracker/my:Category", "my:JobList", compareAssets);

    // Unblock generation of unique keys.
    g_xpathSortBy = "";
    }


    //////////////////////////////////////

    Thanks
  • 01-17-2007 10:16 PM In reply to

    I again Oz,
    Great to see the code. I have some ideas already. It's obviously an xpath issu where g_xpathSortBy seems to be the issue. I'm not sure Sort works the way you are using it, but please provide the schema for the form first and I will look at it some more?
    Patrick Halstead
    Project Manager at Qdabra
  • 01-18-2007 02:53 AM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    Hi again. I'm not sure what you mean by provide schema. Is it this

    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-06T19:05:06" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

    or do you need something else
  • 01-18-2007 03:06 AM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    Sorry. I think you need this.





    Thanks again.
  • 01-18-2007 03:09 AM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    forgot to mention the the button above the checkbox (btnSortChecked) is the only one that currentely does anything. At the end I will do the same for the other buttons.
  • 01-23-2007 05:40 PM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    I'm guessing that this is something that can't be done in Infopath. I'll try to figure out another solution. Good thing that the rest of the functionality is great.
  • 01-24-2007 07:23 PM In reply to

    Hi Oz213,
    Sorry for the delay. It's been busy here and I took the 19th off. Thanks for your patience! You say that the problem is that you can't sort by multiple categories. I only see one job category in the code above. Is this the code that doesn't work? This is definitely possible in InfoPath, but I'm still trying to step through the code in my head to tell you where to make the change.
    Patrick Halstead
    Project Manager at Qdabra
  • 01-24-2007 08:24 PM In reply to

    • oz213
    • Not Ranked
    • Joined on 01-17-2007
    • Posts 11
    Hi Patrick,

    No worries about the delay. Any help is much appreciated and being busy is a good thing. So is taking some time for yourself.

    Hopefully I can explain this a little better. In the examples above there is only one category and one row with job information. Each of them is a repeating table, so when you open the form you have one blank category (which you can name what ever you like) and one blank job. Then, you can add additonal jobs to that category or start a new category.

    Here is a screen shot of a test one started.



    What happens then is if I try to sort the jobs in Category 2 by clicking the Completed (checked) button, it sorts Category 1.

    I hope that made some sense.
Page 1 of 1 (11 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.