1 Reply Latest reply on Jul 28, 2006 6:16 PM by ntsiii

    Problem inserting Checkbox Column dynamically to the DataGrid

    fancycarp
      My Flex application contains a single DataGrid which works with any set of data from my database. When the grid load each set of data I want to insert checkbox column as the first column. But I face some problem.

      At first, I call web service, get data, the event below trigs, each set of data is loaded to grid. It work fine (without the checkbox column). The columns is automatically loaded for each set of data properly.

      private function op_Executed( event : ResultEvent ) : void
      {
      grid.dataProvider = event.result;
      }

      Next, I try to insert the checkbox column

      private function op_Executed( event : ResultEvent ) : void
      {
      grid.dataProvider = event.result;

      //Create checkbox column
      var colChk : DataGridColumn = new DataGridColumn();
      colChk.sortable = false;
      colChk.width = 24;

      //Attach some renderer
      var rdr : ClassFactory
      rdr = new ClassFactory( HeaderCheckBoxRenderer );
      colChk.headerRenderer = rdr

      rdr = new ClassFactory( ItemCheckBoxRenderer );
      colChk.itemRenderer = rdr;

      //Insert checkbox column
      var cols : Array = grid.columns;
      cols.splice( 0, 0, colChk );
      grid.columns = cols;
      }

      The checkbox column is inserted only when the grid loads first set of data. But when I click some button to load next set of data, the checkbox column already exist, so columns list of next set of data is not automatically loaded as done in first time.

      Then, I try to remove the existing checkbox column before each loading

      private function op_Executed( event : ResultEvent ) : void
      {
      //Remove first column
      var a : Array = grid.columns;
      a.splice( 0, a.length );
      grid.columns = a;

      grid.dataProvider = event.result;

      //Create checkbox column
      var colChk : DataGridColumn = new DataGridColumn();
      colChk.sortable = false;
      colChk.width = 24;

      //Attach some renderer
      var rdr : ClassFactory
      rdr = new ClassFactory( HeaderCheckBoxRenderer );
      colChk.headerRenderer = rdr

      rdr = new ClassFactory( ItemCheckBoxRenderer );
      colChk.itemRenderer = rdr;

      //Insert checkbox column
      var cols : Array = grid.columns;
      cols.splice( 0, 0, colChk );
      grid.columns = cols;
      }

      But it also doesn't work. The grid displays only a checkbox column for each loading. This time, grid.dataProvider = event.result; seems not work.

      Any idea?
      Thanks