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

RC1 DataTable question or problem?

Expand Messages
  • Steve
    I installed the RC1 and have found some problems with Datatable which I am unable to overcome. It has to do with getSelectedRows returning invalid rows. I need
    Message 1 of 1 , Jul 31 11:36 AM
      I installed the RC1 and have found some problems with Datatable which
      I am unable to overcome. It has to do with getSelectedRows returning
      invalid rows. I need to to be able to delete some rows in my table.
      The attached code will allow you to create a table. Use the add
      button to add several rows. You can then select a row and delete a
      row. Once you delete the first row in the table, the following rows
      will be offset until, ultimately, you will not be able to delete the
      last row in the table. It appears that the RecordSet is not being
      updated upon delete of a row and this os throwing off the record set
      size. Am I doing something wrong? Is there workaround? Any help is
      appreciated.

      Thanks in advance


      <html>
      <head>
      <title>A test table</title>
      <style type="text/css">
      body {
      margin:0;
      padding:0;
      }
      </style>

      <link rel="stylesheet" type="text/css"
      href="./yui/fonts/fonts-min.css" />
      <link rel="stylesheet" type="text/css"
      href="./yui/datatable/assets/skins/sam/datatable.css" />
      <script type="text/javascript" src="./yui/yahoo-dom-
      event/yahoo-dom-event.js"></script>
      <script type="text/javascript"
      src="./yui/element/element-beta.js"></script>
      <script type="text/javascript"
      src="./yui/datasource/datasource-beta.js"></script>
      <script type="text/javascript"
      src="./yui/datatable/datatable-beta.js"></script>


      <!--begin custom header content for this example-->
      <style type="text/css">
      /* custom styles for this example */
      .yui-skin-sam .yui-dt-body {cursor:pointer;} /* when
      rows are selectable */
      #single {margin-top:2em;}
      </style>

      <!--end custom header content for this example-->
      </head>
      <body class="yui-skin-sam">

      <div id="basic"> </div>
      <script language="JavaScript"
      type="text/javascript">
      var result;
      var myColumnHeaders = [
      {key:"code",
      label:"Code",sortable:true},
      {key:"value",
      label:"Value",sortable:true}];

      var myColumnSet = new
      YAHOO.widget.ColumnSet(myColumnHeaders);
      var myDataSource;
      myDataSource = new
      YAHOO.util.DataSource(result);
      myDataSource.responseType =
      YAHOO.util.DataSource.TYPE_JSARRAY;
      myDataSource.responseSchema = {
      resultNode: "result",

      fields: ["code","value"]};
      var myDataTable = new
      YAHOO.widget.DataTable("basic", myColumnSet, myDataSource,

      {caption:"Test Table",

      scrollable:true,

      selectionMode:"single"
      });


      myDataTable.subscribe
      ("cellClickEvent",myDataTable.onEventEditCell);
      myDataTable.subscribe
      ("cellClickEvent",myDataTable.onEventSelectRow);

      var rowCount=0;
      function addRow() {
      rowCount++;
      var row = "row "+rowCount;
      var myObj =
      {id:'99',code:row,value:row};
      addRecord(myObj);
      }

      function deleteRow() {
      var rows =
      myDataTable.getSelectedRows();
      for (var i=0; i<rows.length;
      i++) {
      var row = rows[i];

      var index =
      myDataTable.getRecordIndex(row);
      myDataTable.deleteRow
      (index);
      }
      myDataTable.refreshView();
      }

      function addRecord(object) {
      var record =
      myDataTable.getRecordSet().addRecord(object);
      myDataTable.addRow(record);
      myDataTable.refreshView();
      }

      </script>
      <button type='button' onclick='addRow()'>Add
      row</button>
      <button type='button' onclick='deleteRow
      ()'>Delete Selected Row</button>
      </body>
      </html>
    Your message has been successfully submitted and would be delivered to recipients shortly.