Loading ...
Sorry, an error occurred while loading the content.

Re: DatataTable updateRow methoc

Expand Messages
  • lou_tribal
    I did something similar but in a different way. I won t tell you that it is the best way, but at least it is simple and working. See the two methods below:
    Message 1 of 5 , Dec 31, 2008
    • 0 Attachment
      I did something similar but in a different way.
      I won't tell you that it is the best way, but at least it is simple and working.
      See the two methods below:

          _moveUp = function()
          {
            var selected = myTable.getRecordSet().
                  getRecord(myTable.getLastSelectedRecord()),
                recordSet = myTable.getRecordSet(),
                selectedIndex= recordSet.getRecordIndex(selected),
                selectedData= selected.getData();
            recordSet.addRecord(selectedData, selectedIndex-1);
            recordSet.deleteRecord(recordSet.getRecordIndex(selected));
          }

          _moveDown = function()
          {
            var selected = myTable.getRecordSet().
                  getRecord(myTable.getLastSelectedRecord()),
                recordSet = myTable.getRecordSet(),
                selectedIndex= recordSet.getRecordIndex(selected),
                selectedData= selected.getData();

            recordSet.addRecord(selectedData, selectedIndex+2);
            recordSet.deleteRecord(recordSet.getRecordIndex(selected));
          }


      <




      --- In ydn-javascript@yahoogroups.com, "Makoki" <makokies@...> wrote:
      >
      > Hi all,
      >
      > I would provide a method to move records (up and down) over the
      > Datatable, so I have wrote moverArriba (moveUp) and moverAbajo
      > (moveDown) functions into my javascript file. I thought that I could do
      > it something like that:
      >
      > var moverArriba=function(ev)
      > { if(gridLites)
      > { var arrRst=gridLites.getSelectedRows();
      > if(arrRst.length>0)
      > { var rstOrigen=gridLites.getRecord(arrRst[0]);
      > if(rstOrigen._nCount>0)
      > { var rstDestino=gridLites.getRecord(rstOrigen._nCount-1);
      > gridLites.updateRow(rstOrigen,rstDestino._oData);
      > }
      > }
      > }
      > else
      > { alert('Debes tener cargado o creado literales para poder desplazar
      > los registros');
      > }
      > }
      >
      > Seem's that updateRow method updates rstOrigen before to place it into
      > Datatable, so rstOrigen and rstDestino has the same information after
      > updateRow method finish. So I can't do
      > gridLites.updateRow(rstDestino,rstOrigen._oData)....
      >
      > ¿Why does updateRow method has this behaviour?.... ¿Do I have
      > replace the information population the data for myself, going through
      > each field of the record and put on it the data?.
      >
      > For now, I've done it with this:
      >
      > var moverArriba=function(ev)
      > { if(gridLites)
      > { var arrRst=gridLites.getSelectedRows();
      > if(arrRst.length>0)
      > { var rstOrigen=gridLites.getRecord(arrRst[0]);
      > if(rstOrigen._nCount>0)
      > { var rstDestino=gridLites.getRecord(rstOrigen._nCount-1);
      > var colGrid=gridLites.getColumnSet();
      > var nomCampo;
      > var valCampoOrigen;
      > var valCampoDestino;
      > for(var a=0; a<3; a++)
      > { nomCampo=colGrid.getColumn(a).getKey();
      > valCampoOrigen=rstOrigen.getData(nomCampo);
      > valCampoDestino=rstDestino.getData(nomCampo);
      > gridLites.updateCell(rstDestino,a,valCampoOrigen);
      > gridLites.updateCell(rstOrigen,a,valCampoDestino);
      > }
      > // I need to replace the enumeration of the records.
      > valCampoOrigen=rstOrigen.getData('ORDLITE');
      > valCampoDestino=rstDestino.getData('ORDLITE');
      > gridLites.updateCell(rstOrigen,0,valCampoDestino);
      > gridLites.updateCell(rstDestino,0,valCampoOrigen);
      > }
      > }
      > }
      > else
      > { alert('Debes tener cargado o creado literales para poder desplazar
      > los registros');
      > }
      > }
      >
      > This is more complicated, but I have not found other way to do that.
      > ¿Any suggestions?
      >
      > Thank's in advice,
      >
      > Ferran.
      >
    • Satyam
      The problem is that when you get a reference to the data in the record, you are not getting a copy of the data, a clone, but a copy of the reference to that
      Message 2 of 5 , Dec 31, 2008
      • 0 Attachment
        The problem is that when you get a reference to the data in the record,
        you are not getting a copy of the data, a clone, but a copy of the
        reference to that same data so they are pointing both to the same
        memory locations where the data is. Variables holding objects are
        reference to the objects, when you assign a variable to an object to
        another variable, you are copying the reference, not the values of the
        objects so if you change the values by some other means, your 'copy'
        (which isn't) gets the new values. In your alternative way, what you
        are doing is copying actual values, in effect creating a sort of clone,
        and you are holding copies of those values, not references to the same
        storage positions. Method YAHOO.lang.merge() is an easy way to make a
        shallow (one level deep) 'clone' of an object.

        By the way, avoid using variables starting with an underscore, they are
        meant to be private and, starting with YUI3, they might also be
        protected. Basically, since JavaScript does not provide privacy, the
        underscore is a convention to denote the intention of making it
        private. Method getData() without arguments, gives you the same result.

        Satyam






        Makoki wrote:
        > Hi all,
        >
        > I would provide a method to move records (up and down) over the
        > Datatable, so I have wrote moverArriba (moveUp) and moverAbajo
        > (moveDown) functions into my javascript file. I thought that I could
        > do it something like that:
        >
        > var moverArriba=function(ev)
        > { if(gridLites)
        > { var arrRst=gridLites.getSelectedRows();
        > if(arrRst.length>0)
        > { var rstOrigen=gridLites.getRecord(arrRst[0]);
        > if(rstOrigen._nCount>0)
        > { var rstDestino=gridLites.getRecord(rstOrigen._nCount-1);
        > gridLites.updateRow(rstOrigen,rstDestino._oData);
        > }
        > }
        > }
        > else
        > { alert('Debes tener cargado o creado literales para poder
        > desplazar los registros');
        > }
        > }
        >
        > Seem's that updateRow method updates rstOrigen before to place it into
        > Datatable, so rstOrigen and rstDestino has the same information after
        > updateRow method finish. So I can't do
        > gridLites.updateRow(rstDestino,rstOrigen._oData)....
        >
        > ¿Why does updateRow method has this behaviour?.... ¿Do I have replace
        > the information population the data for myself, going through each
        > field of the record and put on it the data?.
        >
        > For now, I've done it with this:
        >
        > var moverArriba=function(ev)
        > { if(gridLites)
        > { var arrRst=gridLites.getSelectedRows();
        > if(arrRst.length>0)
        > { var rstOrigen=gridLites.getRecord(arrRst[0]);
        > if(rstOrigen._nCount>0)
        > { var rstDestino=gridLites.getRecord(rstOrigen._nCount-1);
        > var colGrid=gridLites.getColumnSet();
        > var nomCampo;
        > var valCampoOrigen;
        > var valCampoDestino;
        > for(var a=0; a<3; a++)
        > { nomCampo=colGrid.getColumn(a).getKey();
        > valCampoOrigen=rstOrigen.getData(nomCampo);
        > valCampoDestino=rstDestino.getData(nomCampo);
        > gridLites.updateCell(rstDestino,a,valCampoOrigen);
        > gridLites.updateCell(rstOrigen,a,valCampoDestino);
        > }
        > // I need to replace the enumeration of the records.
        > valCampoOrigen=rstOrigen.getData('ORDLITE');
        > valCampoDestino=rstDestino.getData('ORDLITE');
        > gridLites.updateCell(rstOrigen,0,valCampoDestino);
        > gridLites.updateCell(rstDestino,0,valCampoOrigen);
        > }
        > }
        > }
        > else
        > { alert('Debes tener cargado o creado literales para poder
        > desplazar los registros');
        > }
        > }
        >
        > This is more complicated, but I have not found other way to do that.
        > ¿Any suggestions?
        >
        > Thank's in advice,
        >
        > Ferran.
        >
        >
        > ------------------------------------------------------------------------
        >
        >
        > No virus found in this incoming message.
        > Checked by AVG - http://www.avg.com
        > Version: 8.0.176 / Virus Database: 270.10.1/1869 - Release Date: 30/12/2008 12:06
        >
        >
      • Makoki
        Thank you Satyam, Finally I have wrote my function like this: function moverRegistro(destino) { if(gridLites) { var arrRst=gridLites.getSelectedRows();
        Message 3 of 5 , Jan 5, 2009
        • 0 Attachment
          Thank you Satyam,

          Finally I have wrote my function like this:


          function moverRegistro(destino)
          { if(gridLites)
              {    var arrRst=gridLites.getSelectedRows();
                  if(arrRst.length>0)
                  {    var rstOrigen=gridLites.getRecord(arrRst[0]);
                      var condicion=destino=='arriba' ? rstOrigen._nCount>0 : rstOrigen._nCount<gridLites.getRecordSet().getLength()-1;
                      if(condicion)
                      { var rstDestino=destino=='arriba' ? gridLites.getRecord(rstOrigen._nCount-1) : gridLites.getRecord(rstOrigen._nCount+1);
                          var datDestino=rstDestino.getData();
                          gridLites.updateRow(rstDestino,rstOrigen.getData());
                          gridLites.updateRow(rstOrigen,datDestino);
                         // I need to replace the enumeration of the records
                          var valCampoOrigen=rstOrigen.getData('ORDLITE');
                          var valCampoDestino=rstDestino.getData('ORDLITE');
                          gridLites.updateCell(rstOrigen,0,valCampoDestino);
                          gridLites.updateCell(rstDestino,0,valCampoOrigen);
                      }
                  }
              }
              else
              { alert('Debes tener cargado o creado literales para poder desplazar los registros');
              }
          }

          Regards,

          Ferran.

          --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
          >
          > The problem is that when you get a reference to the data in the record,
          > you are not getting a copy of the data, a clone, but a copy of the
          > reference to that same data so they are pointing both to the same
          > memory locations where the data is. Variables holding objects are
          > reference to the objects, when you assign a variable to an object to
          > another variable, you are copying the reference, not the values of the
          > objects so if you change the values by some other means, your 'copy'
          > (which isn't) gets the new values. In your alternative way, what you
          > are doing is copying actual values, in effect creating a sort of clone,
          > and you are holding copies of those values, not references to the same
          > storage positions. Method YAHOO.lang.merge() is an easy way to make a
          > shallow (one level deep) 'clone' of an object.
          >
          > By the way, avoid using variables starting with an underscore, they are
          > meant to be private and, starting with YUI3, they might also be
          > protected. Basically, since JavaScript does not provide privacy, the
          > underscore is a convention to denote the intention of making it
          > private. Method getData() without arguments, gives you the same result.
          >
          > Satyam
          >
          >
          >
          >
          >
          >
          > Makoki wrote:
          > > Hi all,
          > >
          > > I would provide a method to move records (up and down) over the
          > > Datatable, so I have wrote moverArriba (moveUp) and moverAbajo
          > > (moveDown) functions into my javascript file. I thought that I could
          > > do it something like that:
          > >
          > > var moverArriba=function(ev)
          > > { if(gridLites)
          > > { var arrRst=gridLites.getSelectedRows();
          > > if(arrRst.length>0)
          > > { var rstOrigen=gridLites.getRecord(arrRst[0]);
          > > if(rstOrigen._nCount>0)
          > > { var rstDestino=gridLites.getRecord(rstOrigen._nCount-1);
          > > gridLites.updateRow(rstOrigen,rstDestino._oData);
          > > }
          > > }
          > > }
          > > else
          > > { alert('Debes tener cargado o creado literales para poder
          > > desplazar los registros');
          > > }
          > > }
          > >
          > > Seem's that updateRow method updates rstOrigen before to place it into
          > > Datatable, so rstOrigen and rstDestino has the same information after
          > > updateRow method finish. So I can't do
          > > gridLites.updateRow(rstDestino,rstOrigen._oData)....
          > >
          > > ¿Why does updateRow method has this behaviour?.... ¿Do I have replace
          > > the information population the data for myself, going through each
          > > field of the record and put on it the data?.
          > >
          > > For now, I've done it with this:
          > >
          > > var moverArriba=function(ev)
          > > { if(gridLites)
          > > { var arrRst=gridLites.getSelectedRows();
          > > if(arrRst.length>0)
          > > { var rstOrigen=gridLites.getRecord(arrRst[0]);
          > > if(rstOrigen._nCount>0)
          > > { var rstDestino=gridLites.getRecord(rstOrigen._nCount-1);
          > > var colGrid=gridLites.getColumnSet();
          > > var nomCampo;
          > > var valCampoOrigen;
          > > var valCampoDestino;
          > > for(var a=0; a<3; a++)
          > > { nomCampo=colGrid.getColumn(a).getKey();
          > > valCampoOrigen=rstOrigen.getData(nomCampo);
          > > valCampoDestino=rstDestino.getData(nomCampo);
          > > gridLites.updateCell(rstDestino,a,valCampoOrigen);
          > > gridLites.updateCell(rstOrigen,a,valCampoDestino);
          > > }
          > > // I need to replace the enumeration of the records.
          > > valCampoOrigen=rstOrigen.getData('ORDLITE');
          > > valCampoDestino=rstDestino.getData('ORDLITE');
          > > gridLites.updateCell(rstOrigen,0,valCampoDestino);
          > > gridLites.updateCell(rstDestino,0,valCampoOrigen);
          > > }
          > > }
          > > }
          > > else
          > > { alert('Debes tener cargado o creado literales para poder
          > > desplazar los registros');
          > > }
          > > }
          > >
          > > This is more complicated, but I have not found other way to do that.
          > > ¿Any suggestions?
          > >
          > > Thank's in advice,
          > >
          > > Ferran.
          > >
          > >
          > > ------------------------------------------------------------------------
          > >
          > >
          > > No virus found in this incoming message.
          > > Checked by AVG - http://www.avg.com
          > > Version: 8.0.176 / Virus Database: 270.10.1/1869 - Release Date: 30/12/2008 12:06
          > >
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.