How to Get Cell Type

I don’t see a grid function in your API for getting a cell’s type, is there one?

Here is my problem, I am changing cell types on the fly like this (viewtopic.php?f=2&t=34207)…

[code]//change the cell type to an read-only type
mygrid.setCellExcellType(ids_array[i],1,“ro”);

//then set the image value
mygrid.cellById(ids_array[i], 1).setValue(“images/dhtmlx/green.gif”);

//change it to an image type
mygrid.setCellExcellType(ids_array[i],1,“img”);[/code]
After I do that I need to get the NEW VALUES for the cell type’s but if I do this: mygrid.cells(id,1).getAttribute(‘type’);
it still reports their original type “ch”, not “img”, why?

Thanks!

Not sure if support has a way of doing this as the grid is optimized for speed and it looks the grid knows the column type as a whole.

A work-around (one of many) is to use the grid’s userdata storage and save the id when you switch the column type.

docs.dhtmlx.com/doku.php?id=dhtm … ional_data

Then check userdata when needed.

I am not big on the idea having different types in a single column as additional side effects will crop up on you, like it will probably need a custom sort function and who knows what else…

If you need a checkbox column in which certain checkboxes need to show an image instead, consider making the column of type image and then use 3 images: checkbox.png, checkbox_checked.png and disable.png Catch when the column is clicked and then switch image.

There’s nothing wrong with different types per cell: dhtmlx.com/docs/products/dht … xcell.html

My grid works great. I just need this “GETTER” function. They have a “SETTER” function for it, so why not have a matching “GETTER”? I want the getter function so I can see what type of column it is, if it’s a checkbox then I check (or uncheck) it in my “toggle” function. Right now I have a try/catch around that line. It works just fine. But I think solving it using a try/catch is a hack.

toggleAll:function(master_checkbox){ //Have to loop rows this way, can't use forEachRow() because //that will loop rows you can't see (if the user filtered by something) var count = mygrid.getRowsNum(); for (var i=0; i<count; i++){ var id = mygrid.getRowId(i); //instead of doing a try/catch here I want to get the column type //and do an IF statement if it's a checkbox try{mygrid.cells(id,1).setValue(master_checkbox.checked);}catch(e){} }
But I will keep your suggestion in mind (and will probably do that if they can’t come up with a simple way to get the column type). For now I prefer the look and feel of native checkboxes. And working with them is cleaner in my opinion, instead of having to do indexOf on innerHTMLs to find out what image is in place all I have to do is obj.checked.

Most likely there is a getter function which has not been made public.

Dhtmlx is using images for their checkboxes:

dhtmlx.com/docs/products/dht … m_chk1.gif
dhtmlx.com/docs/products/dht … m_chk0.gif

The “space” key is being trapped to toggle between the two images.

If you do go down the route of using images, you could store the checked state inside of userdata each time the image is clicked.

As a followup, it looks like trapping the “space” key is not working so well.

When not in edit mode, the space key triggers a page down event. So trying to catch it with grid’s “onKeypress” event handler is not working for me. I think if there was an onKeyDown event it might work.

I realize that they use images for the checkboxes. But a “ch” type is still different than an “img” type. The eXcell_img object has different properties than the eXcell_ch object. That’s why I have to put a try/catch around my code cause I cannot setValue(0) or setValue(1) on the eXcell_img…

Uncaught TypeError: Object # has no method ‘indexOf’: dhtmlxSuite_v36_pro_131108.js:1117
eXcell_img.setValue: dhtmlxSuite_v36_pro_131108.js:1117

I just want to do this…

if(mygrid.getCellExcellType(rId,1)==='ch') //(or eXcell_ch) mygrid.cells(rId,1).setValue(master_checkbox.checked);
I still would like a response from a DHTMLX programmer on this matter. How do I determine what a cellType is in a grid? That’s all I need. The opposite of: mygrid.setCellExcellType. Something like: mygrid.getCellExcellType. If they say the only way is to use all images then fine. But that will make the code more difficult than it needs to be. Dealing with eXcell_ch types are awesome cause it’s simply 1s and 0s. Having different types in a column shouldn’t be a problem. A getter function would solve this. Thanks.

http://stackoverflow.com/questions/21340463/get-dhtmlx-grid-cell-type

Unfortunately there is no method that gets the cell excell type.
Your issue will be considered, and if it’s available such method may be added to the future version of dhtmlxgrid.

I noticed after version 4.0.3 the problem still exists. To recap, the problem is when a column in a grid starts out as a “ch”, then based on some action I change it to an “img”, after it’s changed to an “img” mygrid.cells(id,1).getAttribute(‘type’) still reports it as a “ch”.

I just noticed the isCheckbox() function. So instead of a try/catch I am now using that.

//looping rows if(mygrid.cells(id,1).isCheckbox()) { //do some action against checkbox rows only }

Its kind of expected.
getAttribute method returns data that was parsed from the original XML ( json ) data feed. It doesn’t return the actual state of grid.

Hi, I have the same problem.
I change the cell type with grid.setCellExcellType and in one column there are diferent cell types.

Based on the grid.setCellExcellType function I implemented this one:

[code]/**

  • @desc: gets excell type for cell in question (based on {@link dhtmlXGridObject.prototype.setCellExcellType} and {@link htmlXGridObject.prototype.changeCellType})
  • @param: rowId - row ID
  • @param: cellIndex - cell index
  • @type: public
  • @returns: {string} type of excell (code like “ed”, “txt”, “ch” etc.)
    */
    dhtmlXGridObject.prototype.getCellExcellType=function(rowId, cellIndex) {
    var row = this.getRowById(rowId);
    var z = this.cells3(row, cellIndex);
    return z.cell._cellType;
    };[/code]

I am using v 4.0.3, is this approach correct?

Thanks

It will work correctly for Grid 4.x and 5.x
Still, beware that _cellType is a private property so grid behavior may change in future.

P.S. We will add getCellExcellType as part of public API in the next update