Setting Excell type from php

Good morning, quick question, hopefully it is something easy and I am just not finding it in the forum or API references.

I have a large editable grid being showed to the end user, a list of tasks if you will. The user is assigned and can click a check box within the grid which will update the database via the php dataconnector. All is working in that department. The issue is that I want the check box to become disabled once the user clicks it, so it can not be unchecked.

Also, since I have the windows login username, I am trying to set up user rights as to which cells they can edit depending on the permissions given. This will also lead me to be able to set cells that can or cannot be edited.

Thank you for your help!

The issue is that I want the check box to become disabled once the user clicks it, so it can not be unchecked.

You can use code like

grid.attachEvent("onCheck", function(id, index){ grid.cells(id, index).setDisabled(true); return true; });

This will also lead me to be able to set cells that can or cannot be edited.

You can define cell types per column or per cell, and for cells which must not be editable set column type as “ro”

dhtmlx.com/docs/products/dht … xcell.html

Thanks for the response. My grid is loaded through a data processor, and the grid configuration is set though GridConfiguration() in php. Since some items are completed and others aren’t, is there a way to disable the already completed items checkbox.

The code you provided works great once you check the box, but doesn’t render the grid with already checked boxes as disabled. (Aka, they can click an already completed item, but then the unchecked box becomes disabled.)

I have tried to use:

$grid -> event -> attach("beforeRender","format");

then use something along the lines of if complete setCellExcellType to ro. But I don’t think it works through php. Is there a work around to this or am I missing how the dataProcessor works. Could I run a beforeRender function within the javascript? I thought once you call the dp.init(mygrid); it would render the whole grid?

Before I posted this, I tried to run a beforeRender in the script, but nothing happened.

app.mygrid.attachEvent("beforeRender", function (id, index) {
        isComplete = app.mygrid.cellById(id, "completed");
        if (isComplete = 1) {
            app.mygrid.cells(id, index).setDisabled(true);
            return true;
        }
        return false;
    });

I am lost haha.

beforeRender is a name of server side even, on client side you can use

app.mygrid.attachEvent("onRowCreated", function (id) { isComplete = this.cellById(id, "completed"); if (isComplete = 1) this.cells(id, index).setDisabled(true); });

I am getting the following errors in javascript:

Uncaught TypeError: Cannot read property '_cellType' of undefined dhtmlx.js:6827
Uncaught TypeError: Cannot read property 'length' of undefined 

I have moved the block before and after the loadXML call, and still receive these errors.

Since my grid is loaded through the phpconnector via loadXML(“connector.php”) I am assuming I will need to pass the XML through onRowCreated 3rd parameter.

this is my javascript code:

app.mygrid.setImagePath("././imgs/");
app.mygrid.setDateFormat("%m/%d/%Y");
app.mygrid.setSkin("dhx_skyblue");
app.mygrid.init();
app.mygrid.enableSmartRendering(true);
app.mygrid.loadXML("connector.php");
app.mygrid.attachEvent("onRowCreated", function (id) {
	isComplete = this.cellById(id, "completed");
	if (isComplete = 1){
		this.cells(id, index).setDisabled(true);
		return true;
	}
});
dp.init(app.mygrid);

by the way, thank you for your patience with me.

Was a my typo, change code as

app.mygrid.attachEvent("onRowCreated", function (id) { isComplete = this.cellById(id, index); if (isComplete = 1){ this.cellById(id, index).setDisabled(true); return true; } });

and replace “index” with index (zero based ) of checkbox column ( so it well be cellById(id,3) - or something similar )

We are getting closer. But this time every box is disabled. I found that this.cellByID(id, 8) returns an object vice what the cell value is, so I can not evaluate it as 1 or 0.

Sorry for typo, it must be

isComplete = this.cellById(id, index).getValue();

Victory!

app.mygrid.attachEvent("onRowCreated", function (id) {
	isComplete = this.cellById(id,8).getValue();
	if (isComplete == "1"){
		this.cellById(id, 8).setDisabled(true);
		return true;
	}
});

My last problem with code provided:
isComplete is now a number, 0 or 1. But if(isComplete = 1) was always geting called, even when isComplete is 0.

So I thought that maybe the value was being returned as a string, and sure enough, it was. So I changed the = 1 to == “1”. By the way…is this correct? As in is it supposed to return a string?

Now any checkbox that was already completed is greyed out, and any checkbox that is unchecked is able to be checked, and once checked, will be greyed out.

Thank you very much for all your help!!!

The problem was not in a string conversion. The original code is

if (isComplete = 1) {

The fixed code will be

if (isComplete == 1) {

Comparation instead of assignment. ( solution with == “1” will work fine as well, because of automatic type conversion )