Jump to content

Get Grid cell / grid row


tappatappa
 Share

Recommended Posts

 

Hi Nefasto Cipa. 
 
You have found a solution?

 

 

Not yet.

 

 

Since you change the color of cell in your code, you must already know the last color you have set.

 

No offense but this is a lazy answer. The choice of the cell colors can be made after the execution of a (maybe complex) function. In software programming you use the output of a function as input for other functions, all the time. Secondly, maybe the programmer is aware of the logic behind the coloration of the cells, but what about encapsulation (OO programming)? How about a randomly colored grid? I can go on forever...

 

(when I say "after the call of OnDrawColumnCell" I mean after ALL the cells are colored, not immediately after the single call)

 

With that said, I do not consider this to be a major issue, I can work around that for now.

Link to comment
Share on other sites

  • Administrators

Whether it is outcome of a complex function or a random value it can be saved in an array and referred to later. A grid cell has many attributes which many of them are available on client side only. Saving them on server side memory is neither desired nor required. Framework must be optimized to reduce memory usage as much as possible.

  • Upvote 1
Link to comment
Share on other sites

Hi Nefasto Cipa. 
 
Of course, maybe it's not the best solution, but try, the result is returns the HEX value: 
 
1. 
type MyHackDBGrid = class(TUniDBGrid)
end;
....

  public
    { Public declarations }
    ....
    cellStartID: Integer;
    cellBG: string;
  end;

2. UniDBGrid1 -> ClientEvents -> ExtEvents add function store.load (Ext.data.Store [store])

function store.load(sender, records, successful, eOpts){  
  ajaxRequest(this, "_load", ["cellStartID=" + Ext.get(sender.grid.id).down("td").id.substr(7,15)]);
}

3. 

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TStrings);
begin
  if EventName = '_load' then begin    
    cellStartID := StrToInt(Params.Values['cellStartID']);
  end
  else if EventName = '_getBG' then begin
    cellBG := Params.Values['_getBG'];
    //Your custom logic
    ShowMessage(cellBG);
  end;
end;

How to use?

 

for example:

procedure TMainForm.UniButton1Click(Sender: TObject);
var
  colIndx, rowIndx: Integer;
  cellID: Integer;
  gridJSName: string;
  lastColIndx, lastRowIndx: Integer;
begin  
  gridJSName := UniDBGrid1.JSName;
  lastColIndx := MyHackDBGrid(UniDBGrid1).CurrCol;
  lastRowIndx := MyHackDBGrid(UniDBGrid1).CurrRow;
  colIndx := 0; //StrToInt(UniEdit4.Text); 
  rowIndx := 0; //StrToInt(UniEdit5.Text); 
  if rowIndx > 0 then cellID := cellStartID + (rowIndx * UniDBGrid1.Columns.Count) + colIndx
  else cellID := cellStartID + colIndx;  
  UniSession.AddJS(gridJSName + '.getSelectionModel().deselect(); ajaxRequest('+gridJSName+', "_getBG", ["_getBG=" + Ext.draw.Color.toHex(Ext.get("ext-gen'+ IntToStr(cellID) +'").getStyle("background-color"))]);');
  MyHackDBGrid(UniDBGrid1).CurrRow := lastRowIndx;
  MyHackDBGrid(UniDBGrid1).CurrCol := lastColIndx;
end;
 
Sincerely.
Link to comment
Share on other sites

Whether it is outcome of a complex function or a random value it can be saved in an array and referred to later. A grid cell has many attributes which many of them are available on client side only. Saving them on server side memory is neither desired nor required. Framework must be optimized to reduce memory usage as much as possible.

 

I understand that. No problem. As I said: I can live without this feature for now.

 

@Delphi Developer

 

Wow. This is quite an hardcore approach!

Link to comment
Share on other sites

@Delphi Developer

 

Wow. This is quite an hardcore approach!

 

I agree with you, but I don't see another approach. :)

Of course, you can still use a dynamic array on the server side. But as said Farshad, it can require a lot of memory resources ...

 

Although, in the future may Farshad will add this feature as selectively (optional)

Best regards

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...