Custom RowID by jsArray

Hello Everyone

I was wandering if it is possible to assign a custome RowID while using parse() with a jsarray.

All documentation i could found described the array syntax as following:

var arr = [[col1,col2,col3],[col1row2,col2row2,col3row2]];

You can add custome rowID’s via XML but is it also possible via jsarray?

Sincerly
JavaKiddy

Unfortunately such feature is not available.
You may try to use JSON or you can add the ID to the row with setRowId() API-method:
http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:api_method_dhtmlxgridobject_setrowid

Also you may try to load grid from CSV-string. It’s available to set the id of a row in CSV.
Here is the example:
http://www.dhtmlx.com/docs/products/dhtmlxGrid/samples/12_initialization_loading/13_pro_load_csv.html

Just wondering if anything new may have surfaced regarding rowids when loading with jsarray.

I use jsarray data a lot. I was hoping that the rowid column could be set with:

grid.setColumnIds('id','status');

or

grid.setColumnIds('rowid','status');

This does not seem to work.

Could you clarify what you need to change?

For changing the row id you may use changeRowId() method:
docs.dhtmlx.com/doku.php?id=dhtm … hangerowid

To set the ids for all the columns you may use the setColumnIds() method:
docs.dhtmlx.com/doku.php?id=dhtm … tcolumnids

To set the id to a single column setColumnId() method can be used:
docs.dhtmlx.com/doku.php?id=dhtm … etcolumnid

When a grid is loaded via a jsarray, such as:
dhtmlx.com/docs/products/dht … array.html

The id of the row is sequentially numbered. (jsarray data contains only data and has no field identification–unlike json/xml.)

Oftentime, I use jsarray datafeeds and the first column contains my row id and I want to use functions like selectRowById()…which fail.

I was hoping that when I define the grid, I could set the column id with:

   grid.setColumnIds('id','name','address', 'zip');
   grid.setColTypes('ron,ro,ro,fo);

And then load the data via grid.parse(data,‘jsarray’) and the grid would know that column 0 is id and then selectRowById() would work using the data in column0.

Unfortunately such feature is not available.

If you can squeeze this change into the v4, that would be idea. I am looking forward to v4!

Unfortunately we’re not planning to include such feature in the future versions of dhtmlxgrid but such customization may be created.
Please, open ticket with the request at support.dhtmlx.com

Thank you for your help. I will open a support ticket in the near future.

I just created this prototype to help solve my issue:

dhtmlXGridObject.prototype.selectByIdCol0 = function(col0Id, fireOnSelect, preserve, show){	
   if (fireOnSelect == undefined)  fireOnSelect  = false;
   if (preserve == undefined)      preserve      = false;
   if (show == undefined)          show          = true;
   var id
   
   for (id=0; id < this.getRowsNum(); id++){
    if (this.cells(id+1,0).getValue() == col0Id) {
      this.selectRow(id, fireOnSelect, preserve, show);
      break;
    }
  }
}

With a few prototypes, I think my headaches go away. I have not tested this when the grid is being filtered. Pretty sure dhtmlx is robust to handle it.

This looks like the correct solution:

dhtmlXGridObject.prototype.selectByC0Id = function(col0Id, fireOnSelect, preserve, show){	
  if (fireOnSelect == undefined)  fireOnSelect  = false;
  if (preserve == undefined)      preserve      = false;
  if (show == undefined)          show          = true;
  
  var id
  for (id=0; id < this.getRowsNum(); id++){
    if (this.cells(this.getRowId(id),0).getValue() == col0Id) {
      this.selectRow(id, fireOnSelect, preserve, show);
      break;
    }
  }
}