Row Position...again - InfoPath Dev
in

InfoPath Dev

Row Position...again

Last post 07-25-2006 02:08 PM by kikkoman. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 03-21-2006 01:08 PM

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26

    Row Position...again

    I need the current row position for a repeating table in JScript...I've looked at the code & rules from Greg Collins' posts & samples,but can't figure it out for use w/o a ddlb...I think I want something similar to the preceding-sibling stuff?? But how does that translate into JS? Using an OnAfterChange event with this snippet:


    var sPiece = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail[2]/@Piece");

    [2] always selects the 2nd row- but I need a variable there

    var iRow = ?????????

    so I can use
    var sPiece = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail[iRow]/@Piece");
  • 03-21-2006 01:22 PM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    Sorry-I left out this:

    I am trying to get the row position after clicking a button on the repeating table row.....so event.Obj.Site doesnt work
  • 03-23-2006 05:41 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    The proper syntax for what I want to use is:
    var sPiece = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail[" + iRow + "]/@Piece");


    I can get iRow by looping thru the node looking for a match on @Piece - as long as sPiece is unique to the node list - kind of kludgey...and slow...I think what is needed is a property of objEvent that would provide the row of the repeating section that the control fired from...

    function getRowIndex(sPiece)
    {
    var dom = XDocument.DOM;
    var lines = dom.selectNodes("/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail");

    // loop through each line item searching for the matching Piece...
    iRow = 1;
    while (iRow <= lines.length) {
    var xPath = "/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail[" + iRow + "]/@Piece"
    var sVariable= getNodeValue(xPath);
    if (sVariable == sPiece) {
    break
    }
    iRow++;
    }
    return(iRow);
    }

    /*------------------------------------------------------------------------------
    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;
    }
  • 03-23-2006 06:43 AM In reply to

    Hi brandt,
    First go to the following link to Assign an Autogenerated Row Number to a Repeating Field say RowNumber.
    http://www.infopathdev.com/howto/tutorials/default.aspx?i=d663d7df90e94e65abb02632966e8127
    Now all the rows will have the RowNumber field populated with row numbers.

    Now on the click of a button present in the row...
    use the following code to access the row number.
    example in C#...
    string strRowNumber=e.Source.selectSingleNode("my:RowNumberEditable").nodeTypedValue.ToString();

    Sorry for the example in C#.I think the one in JScript should be similar.I think u need to use "eventObj" instead of "e".

    Regards,
    Abhishek
  • 03-23-2006 08:58 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    tnx...that seems to id the row properly...but how can I determine that vale from just a button click from that row....if I can't get to it from eventObj...can I use a rule to set a global variable in JS?
  • 03-23-2006 09:08 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    or even a 2ndairy data source that I can refer back to in code...maybe a rule setting a field in the 2ndairy ds...but how to make sure I get the value from the current row...ie the row from which the btn was clicked?
  • 03-24-2006 03:51 AM In reply to

    Hi Brandt,
    I am unable to understand what u want?
    Can u be more clear?
    Place the code I gave u in the event handler(OnClick) of the button.
    Using e.Source... allows u to access the value of any fields in that row from where u clicked the button.
    Example:
    If u click the button in the 5th row,then using e.source will get u the data contained in the fields of the 5th row.

    And u need to use eventObj instead of e in JScript.

    Regards,
    Abhishek
  • 03-24-2006 05:56 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    buttons have no value...here's what I wound up doing:
    1) create a placeholder field in my detail table (make it hidden) and give it a default value using:
    count(../preceding-sibling::d:tblRADetail/@Piece) + 1 (you can pick any field from the row)
    2)create a 2ndairy ds called Support with one element RowPosition...this is an external resource file...actually I used Greg Collins' example...Support.xml
    3)create a rule on the button(s) to set Suport/RowPosition to the default value of my placeholder field
    4)in the button's OnAfterChange event go get the value of Support/RowPosition...since the rule runs b4 the code this gives me the row position just by pressing the button...and I can use it as an array index to work with the row's fields.

    No wonder this stuff is slow as mud.

    We need a property of eventObj that returns the row index of the repeating group.
  • 03-24-2006 06:22 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    Still trying your way...I always get the value of the first row using:
    var x = eventObj.Source.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail/@placeholderfield").text;
    XDocument.UI.Alert("x:" + x);
  • 03-26-2006 09:13 PM In reply to

    Hi Brandt.
    I got the mistake u have done.

    When u use e.Source or eventObj.Source, u r not supposed to use the full XPath of ur field.

    U should just give the field name since eventObj.Source already points to the repeating group.

    So the right thing to use is
    eventObj.Source.selectSingleNode("<Field name>").text

    Example of the one I use in C#
    string strRowNumber=e.Source.selectSingleNode("my:RowNumber").nodeTypedValue.ToString();


    Let me know if u got it right
    Regards,
    Abhishek

  • 03-27-2006 06:50 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    seems to work! Thanks!

    So...either I
    1)sacrifice a data field of a repeating group OR
    2)create an external structure to hold the value....hmmm slow

    neither is an elegant solution..I'll probably sacrifice a data field to get as much speed as possible.

    I still say that MS needs to provide a property of eventObj that holds the row - then we wont have to sacrifice a data field, and add rules & code to figure it out.

    Thanks for your help though!
  • 07-25-2006 02:08 PM In reply to

    hello everyone!

    i'm having trouble trying to get the value of a repeating row. what i want to do is in the repeating row, i have a check box field and when users check that field, i want to get the value of a field in the same row and copy it to another field in the same row. i'm calling my code in the On_After_Change of the check box field. Here's a simple schema:


    my:a_group
    my:a_group2 (repeating)
    my:Number
    my:override
    my:aDatefield
    my:anotherDatefield


    So in that function. i tried

    public void override_OnAfterChange(DataDOMEvent e)
    {
    IXMLDOMNode the_node = e.Site.selectSingleNode("my:aDatefield");
    string node_value = the_node.text;
    }

    This does not work, it always says it doesn't exist. i searched the forums and there were plenty of discussions on this topic and i tried e.Source, but that didn't work either. i saw on one post that: "e.Site will always have a reference to the node, where as e.Source will have reference to the node or attribute whose value has changed.:

    I tried changing to the whole Xpath but that doesn't work either. I know that you can just go straight to the node of the current row in the repeating section by just specifying the field name ("my:aDatefield") instead of the whole xpath, but its not working. I also tried ("//my:aDatefield") and other numerous combinations but I'm doing something wrong in my xpath.

    I can get the value by using this:


    string strRowNumber = e.Site.nextSibling.nextSibling.nextSibling.nextSibling.text;

    But I know you should never do this because if you add a field to the repeating group in the schema, this would be referencing the wrong field.

    Can someone please help me on this? I know this subject has been brought up alot, but i just can't seem to figure it out. I'm assuming its the xpath! Anyhow, any comments are greatly appreciated!
    thanks in advance,
    ================
    DOH! I can just use rules behind my field to set the value of one field to another in the repeating group. I can't believe I did not think of this. I've been doing this all along for other stuff, but I don't know why I totally forgot. Anyhow, if anyone does know the xpath just in case i need it for some odd reason, that would be great! DOH!!!! on me!
Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.