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

how to find row index to delete

Expand Messages
  • omerorhan80
    whenever i delete a record from my database, i post back ID of it. And i want to delete related record from my datatable. here is my code. var myColumnDefs = [
    Message 1 of 7 , Nov 29, 2008
      whenever i delete a record from my database, i post back ID of it.
      And i want to delete related record from my datatable.

      here is my code.
      var myColumnDefs = [
      {
      key:"id",
      label:"ID",
      sortable:true
      },
      {
      key:"langs",
      label:"Language"
      }
      ];
      For example:

      my deleted record ID = 5;
      i want to remove the row whose ID is "5";
      But, i couldn't find related row.

      var recordSet = myDataTable.getRecordSet();
      //var column = myDataTable.getColumn("id");
      var rec = recordSet.getRecord(XXX);
      var index = recordSet.getRecordIndex(rec);
      myDataTable.deleteRow(index);
    • santini.alberto
      ... I think you are looking for recordSet = myDataTable.getRecordSet(); rec = recordSet.getRecord(XXX); id = rec.getData( id ); Regards, Alberto
      Message 2 of 7 , Nov 29, 2008
        --- In ydn-javascript@yahoogroups.com, "omerorhan80" <omerorhan80@...>
        wrote:
        > var recordSet = myDataTable.getRecordSet();
        > //var column = myDataTable.getColumn("id");
        > var rec = recordSet.getRecord(XXX);
        > var index = recordSet.getRecordIndex(rec);
        > myDataTable.deleteRow(index);
        >

        I think you are looking for

        recordSet = myDataTable.getRecordSet();
        rec = recordSet.getRecord(XXX);
        id = rec.getData("id");

        Regards,
        Alberto
      • omerorhan80
        Thank you for your reply Alberto. But i couldn t get record. rec = recordSet.getRecord(XXX); what should XXX be ?
        Message 3 of 7 , Nov 29, 2008
          Thank you for your reply Alberto.

          But i couldn't get record.

          rec = recordSet.getRecord(XXX);
          what should XXX be ?


          --- In ydn-javascript@yahoogroups.com, "santini.alberto"
          <albertosantini@...> wrote:
          >
          >
          > --- In ydn-javascript@yahoogroups.com, "omerorhan80" <omerorhan80@>
          > wrote:
          > > var recordSet = myDataTable.getRecordSet();
          > > //var column = myDataTable.getColumn("id");
          > > var rec = recordSet.getRecord(XXX);
          > > var index = recordSet.getRecordIndex(rec);
          > > myDataTable.deleteRow(index);
          > >
          >
          > I think you are looking for
          >
          > recordSet = myDataTable.getRecordSet();
          > rec = recordSet.getRecord(XXX);
          > id = rec.getData("id");
          >
          > Regards,
          > Alberto
          >
        • omerorhan80
          console gives me the index like below. But nothings deleted. I don t know why. var records = myDataTable.getRecordSet().getRecords(); for(i in records){
          Message 4 of 7 , Nov 29, 2008
            console gives me the index like below.
            But nothings deleted.

            I don't know why.


            var records = myDataTable.getRecordSet().getRecords();
            for(i in records){
            if(records[i]._oData.id == msg.id)
            {
            myDataTable.deleteRow(i);
            }
            }
            console.log(i);


            --- In ydn-javascript@yahoogroups.com, "omerorhan80" <omerorhan80@...>
            wrote:
            >
            > Thank you for your reply Alberto.
            >
            > But i couldn't get record.
            >
            > rec = recordSet.getRecord(XXX);
            > what should XXX be ?
            >
            >
            > --- In ydn-javascript@yahoogroups.com, "santini.alberto"
            > <albertosantini@> wrote:
            > >
            > >
            > > --- In ydn-javascript@yahoogroups.com, "omerorhan80" <omerorhan80@>
            > > wrote:
            > > > var recordSet = myDataTable.getRecordSet();
            > > > //var column = myDataTable.getColumn("id");
            > > > var rec = recordSet.getRecord(XXX);
            > > > var index = recordSet.getRecordIndex(rec);
            > > > myDataTable.deleteRow(index);
            > > >
            > >
            > > I think you are looking for
            > >
            > > recordSet = myDataTable.getRecordSet();
            > > rec = recordSet.getRecord(XXX);
            > > id = rec.getData("id");
            > >
            > > Regards,
            > > Alberto
            > >
            >
          • santini.alberto
            ... I iterate through the datatable, for instance, with the following code: recordSet = myDataTable.getRecordSet(); for (i = 0; i
            Message 5 of 7 , Nov 29, 2008
              --- In ydn-javascript@yahoogroups.com, "omerorhan80" <omerorhan80@...>
              wrote:
              > But i couldn't get record.
              >
              > rec = recordSet.getRecord(XXX);
              > what should XXX be ?

              I iterate through the datatable, for instance, with the following code:

              recordSet = myDataTable.getRecordSet();
              for (i = 0; i < recordSet.getLength(); i = i + 1) {
              id = recordSet.getRecord(i).getData("id");
              }

              If you want to delete a specific line of the datable, I imagine there
              is an event attached as cellClickEvent and inside the subscribe
              function you could write:

              this.deleteRow(this.getRecord(ev.target))

              where ev is the parameter of the function.

              Hope that helps,
              Alberto.
            • jennykhan
              Hi omerorhan80, You ll need to iterate over all Records to find the one to remove and then remove it by RecordSet index: var allRecords =
              Message 6 of 7 , Dec 1, 2008
                Hi omerorhan80,

                You'll need to iterate over all Records to find the one to remove
                and then remove it by RecordSet index:

                var allRecords = myDataTable.getRecordSet().getRecords();
                for(var i=0; i<allRecords.length; i++) {
                if(allRecords[i].getData("id") === 5) {
                myDataTable.deleteRow(i);
                break;
                }
                }

                Hope that helps,
                Jenny




                --- In ydn-javascript@yahoogroups.com, "omerorhan80"
                <omerorhan80@...> wrote:
                >
                > whenever i delete a record from my database, i post back ID of it.
                > And i want to delete related record from my datatable.
                >
                > here is my code.
                > var myColumnDefs = [
                > {
                > key:"id",
                > label:"ID",
                > sortable:true
                > },
                > {
                > key:"langs",
                > label:"Language"
                > }
                > ];
                > For example:
                >
                > my deleted record ID = 5;
                > i want to remove the row whose ID is "5";
                > But, i couldn't find related row.
                >
                > var recordSet = myDataTable.getRecordSet();
                > //var column = myDataTable.getColumn("id");
                > var rec = recordSet.getRecord(XXX);
                > var index = recordSet.getRecordIndex(rec);
                > myDataTable.deleteRow(index);
                >
              • omerorhan80
                Thank you for your answers. What i did with onCellClick : var onCellClick = function(oArgs) { var ev = YAHOO.util.Event.getEvent(oArgs.event); var target =
                Message 7 of 7 , Dec 2, 2008
                  Thank you for your answers.

                  What i did with onCellClick :

                  var onCellClick = function(oArgs) {

                  var ev = YAHOO.util.Event.getEvent(oArgs.event);
                  var target = YAHOO.util.Event.getTarget(ev);
                  var parent = target.parentNode;
                  var datatable = this;

                  YAHOO.util.Event.preventDefault(ev);

                  var handleYes = function() {
                  this.hide();

                  YAHOO.util.Connect.asyncRequest(
                  'GET',
                  parent.href,
                  {
                  success: function (o) {
                  console.log(this);
                  console.log(o.responseText);
                  datatable.deleteRow(target);
                  },
                  failure: function (o) {
                  alert(o.statusText);
                  },
                  scope:this
                  });

                  };

                  var handleNo = function() {
                  this.hide();
                  };


                  dialog = new YAHOO.widget.SimpleDialog("diyalog_container",
                  { width: "300px",
                  fixedcenter: true,
                  visible: false,
                  draggable: false,
                  close: true,
                  text: "Sure to delete?",
                  icon: YAHOO.widget.SimpleDialog.ICON_HELP,
                  constraintoviewport: true,
                  buttons: [ {text:"Evet", handler: handleYes, isDefault:true
                  },{text:"HayĆ½r", handler: handleNo} ]
                  } );
                  silme_diyalog.setHeader("Confirm");

                  // Render the Dialog
                  silme_diyalog.render("doc3");
                  switch (parent.className) {
                  case 'deletable':
                  dialog.show();
                  break;
                  case 'editable':
                  break;
                  case 'photo':
                  break;
                  }
                  };


                  But i am not sure if it's "OK" when i initialize my dialog and it's
                  button handlers in onCellClick function.


                  --- In ydn-javascript@yahoogroups.com, "omerorhan80" <omerorhan80@...>
                  wrote:
                  >
                  > whenever i delete a record from my database, i post back ID of it.
                  > And i want to delete related record from my datatable.
                  >
                  > here is my code.
                  > var myColumnDefs = [
                  > {
                  > key:"id",
                  > label:"ID",
                  > sortable:true
                  > },
                  > {
                  > key:"langs",
                  > label:"Language"
                  > }
                  > ];
                  > For example:
                  >
                  > my deleted record ID = 5;
                  > i want to remove the row whose ID is "5";
                  > But, i couldn't find related row.
                  >
                  > var recordSet = myDataTable.getRecordSet();
                  > //var column = myDataTable.getColumn("id");
                  > var rec = recordSet.getRecord(XXX);
                  > var index = recordSet.getRecordIndex(rec);
                  > myDataTable.deleteRow(index);
                  >
                Your message has been successfully submitted and would be delivered to recipients shortly.