missing the row id after sort

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • datapartners
    New Member
    • Oct 2007
    • 6

    missing the row id after sort

    I have two iframes on a page that display a table which contain checkboxes that when ticked delete the row.

    Everything works fine expect when I sort one of the tables in the iframe. I set the id attribute each time and when I view the HTML in a debugger the row id is set to the new id.

    When I select the checkbox to delete the sorted row using

    [CODE=javascript]var frameName = document.getEle mentById('view1 ').contentWindo w;
    frameName.docum ent.getElementB yId(rowId).rowI ndex;[/CODE]

    I get an object error, any idea’s ?
    Last edited by gits; Oct 11 '07, 10:02 AM. Reason: added code tags
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by datapartners
    I have two iframes on a page that display a table which contain checkboxes that when ticked delete the row.

    Everything works fine expect when I sort one of the tables in the iframe. I set the id attribute each time and when I view the HTML in a debugger the row id is set to the new id.

    When I select the checkbox to delete the sorted row using

    var frameName = document.getEle mentById('view1 ').contentWindo w;
    frameName.docum ent.getElementB yId(rowId).rowI ndex;

    I get an object error, any idea’s ?

    Alert this "frameName.docu ment.getElement ById(rowId)".
    See whether it returns "undefined" .
    If possible, send the "Sorting" code.

    Debasis Jana.

    Comment

    • datapartners
      New Member
      • Oct 2007
      • 6

      #3
      on the alert returned null

      [CODE=javascript]function fillArray(view ,column){
      var frameName = document.getEle mentById(view). contentWindow;
      for (var i = 0; i < frameName.docum ent.getElementB yId('View').row s.length; i++){
      var Col1 = frameName.docum ent.getElementB yId('View').row s[i].cells[0].innerHTML;
      var Col2 = frameName.docum ent.getElementB yId('View').row s[i].cells[1].innerHTML;
      var Col3 = frameName.docum ent.getElementB yId('View').row s[i].cells[2].innerHTML;
      var Col4 = frameName.docum ent.getElementB yId('View').row s[i].cells[3].innerHTML;
      [Lines.length++] = new Line(col1, col2, col3, col4);
      }
      sortList(view ,column)
      }

      function Lines(col1, col2, col3, col4) {
      this.Col1 = col1;
      this.Col2 = col2;
      this.Col3 = col3;
      this.Col4 = col4;
      }

      function sortTable(view) {
      var frameName = document.getEle mentById(view). contentWindow;
      var counter = Lines.length - 1;
      for (var i = 0; i <= counter; i++){
      frameName.docum ent.getElementB yId('View').row s[i].setAttribute(' id', Lines[i].Col1);
      frameName.docum ent.getElementB yId('View').row s[i].cells[0].innerHTML = Lines[i].Col1;
      frameName.docum ent.getElementB yId('View').row s[i].cells[1].innerHTML = Lines[i].Col3;
      frameName.docum ent.getElementB yId('View').row s[i].cells[2].innerHTML = Lines[i].Message;
      frameName.docum ent.getElementB yId('View').row s[i].cells[3].innerHTML = Lines[i].Col4;
      }
      Lines.length = 0;
      }[/CODE]
      Last edited by gits; Oct 11 '07, 10:02 AM. Reason: added code tags

      Comment

      • datapartners
        New Member
        • Oct 2007
        • 6

        #4
        Ooops function Lines should have been Line

        [CODE=javascript]function Line(col1, col2, col3, col4) {
        this.Col1 = col1;
        this.Col2 = col2;
        this.Col3 = col3;
        this.Col4 = col4;
        }[/CODE]
        Last edited by gits; Oct 11 '07, 10:03 AM. Reason: added code tags

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by datapartners
          on the alert returned null

          function fillArray(view ,column){
          var frameName = document.getEle mentById(view). contentWindow;
          for (var i = 0; i < frameName.docum ent.getElementB yId('View').row s.length; i++){
          var Col1 = frameName.docum ent.getElementB yId('View').row s[i].cells[0].innerHTML;
          var Col2 = frameName.docum ent.getElementB yId('View').row s[i].cells[1].innerHTML;
          var Col3 = frameName.docum ent.getElementB yId('View').row s[i].cells[2].innerHTML;
          var Col4 = frameName.docum ent.getElementB yId('View').row s[i].cells[3].innerHTML;
          [Lines.length++] = new Line(col1, col2, col3, col4);
          }
          sortList(view ,column)
          }

          function Lines(col1, col2, col3, col4) {
          this.Col1 = col1;
          this.Col2 = col2;
          this.Col3 = col3;
          this.Col4 = col4;
          }

          function sortTable(view) {
          var frameName = document.getEle mentById(view). contentWindow;
          var counter = Lines.length - 1;
          for (var i = 0; i <= counter; i++){
          frameName.docum ent.getElementB yId('View').row s[i].setAttribute(' id', Lines[i].Col1);
          frameName.docum ent.getElementB yId('View').row s[i].cells[0].innerHTML = Lines[i].Col1;
          frameName.docum ent.getElementB yId('View').row s[i].cells[1].innerHTML = Lines[i].Col3;
          frameName.docum ent.getElementB yId('View').row s[i].cells[2].innerHTML = Lines[i].Message;
          frameName.docum ent.getElementB yId('View').row s[i].cells[3].innerHTML = Lines[i].Col4;
          }
          Lines.length = 0;
          }
          I think this line will be ...........
          [code=javascript]
          //[Lines.length++] = new Line(col1, col2, col3, col4);
          Lines[length++] = new Line(col1, col2, col3, col4);
          [/code]

          Debasis Jana

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by datapartners
            Ooops function Lines should have been Line

            function Line(col1, col2, col3, col4) {
            this.Col1 = col1;
            this.Col2 = col2;
            this.Col3 = col3;
            this.Col4 = col4;
            }
            And what is "Lines"??
            Please Let me know.

            Debasis Jana

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5388

              #7
              heya datapartners,

              please use code tags when posting source-code:

              &#91;CODE=javas cript] your code here [/CODE]

              kind regards

              Comment

              • datapartners
                New Member
                • Oct 2007
                • 6

                #8
                Thanks for the tips so far ... from testing it appears that the line below is causing the problem;-

                Code:
                 frameName.document.getElementById('View').rows[i].setAttribute('id', Lines[i].Col1);
                I have commented out the line above from the code and the getElementById( ) was defined, and could delete a row after the sort was performed but deleted the wrong line.

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by datapartners
                  Thanks for the tips so far ... from testing it appears that the line below is causing the problem;-

                  Code:
                   frameName.document.getElementById('View').rows[i].setAttribute('id', Lines[i].Col1);
                  I have commented out the line above from the code and the getElementById( ) was defined, and could delete a row after the sort was performed but deleted the wrong line.
                  Check out that whether those Rows updated with desired "ID".

                  Debasis Jana

                  Comment

                  • datapartners
                    New Member
                    • Oct 2007
                    • 6

                    #10
                    Problem solved it appears that when the new id was set by the setAttribute from the array it also added white spaces too. I wrote a trim function

                    Code:
                       //---------------------------------------------------------------------------------------->
                       //---                               Function Left Trim                         --->
                       //---------------------------------------------------------------------------------------->  
                    function LTrim( value ) {
                    	var re = /\s*((\S+\s*)*)/;
                    	return value.replace(re, "$1");
                    }
                    
                       //---------------------------------------------------------------------------------------->
                       //---                               Function Right Trim                       --->
                       //---------------------------------------------------------------------------------------->  
                    function RTrim( value ) {
                    	var re = /((\s*\S+)*)\s*/;
                    	return value.replace(re, "$1");
                    }
                    
                       //---------------------------------------------------------------------------------------->
                       //---                                  Function Trim                            --->
                       //---------------------------------------------------------------------------------------->  
                    function trim( value ) {
                    	return LTrim(RTrim(value));
                    }
                    added it to the


                    Code:
                    frameName.document.getElementById('View').rows[i].setAttribute('id', trim(Lines[i].Col1));
                    and works like a charm, thanks to all concerned.

                    Comment

                    Working...