Jump to content

StringGrid Questions


mos

Recommended Posts

I have a number of questions:

 

  1. Is there a way of preventing the user from resizing the column below a minimum column width value so that the column is always visible?
  2. Is it possible to drag and drop columns to change the ordering of the columns in the grid?
  3. How can rows be sorted in ascending/descending order based on the column that is clicked?  I have seen sorting code based on the VCL stringgrid which uses the Rows property and a temporary TStringList to perform the exchanging of the rows however the uniGUI stringgrid does not have this property.
Link to comment
Share on other sites

Just bumping this.

 

Also I have another question:

 

    4.   How can I update the UniCellAttribs of a cell without using OnDrawCell event?  e.g. I have a timer which runs and I want to update a particular Cell background color based on a certain condition.

Link to comment
Share on other sites

Hi,

 

4.   How can I update the UniCellAttribs of a cell without using OnDrawCell event?  e.g. I have a timer which runs and I want to update a particular Cell background color based on a certain condition.

 

One possible solution,

Can you try to use this approach?:

 

For example for Row=0 (tr:nth(1)) and Column=0 (td:nth(1))

 

nth(n) (1 based)

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniStringGrid1.JSInterface do
  begin
    JSCode(#1'.normalGrid.getView().el.select("tr:nth(1) td:nth(1)").elements[0].style["background-color"]="green";');
    JSCode(#1'.normalGrid.getView().el.select("tr:nth(1) td:nth(1)").elements[0].style["color"]="white";');
  end;
end;

Best regards,

Link to comment
Share on other sites

Ok,

 

Try this:

  with UniStringGrid1.JSInterface do
  begin
    JSCode('var view, me='#1'; if(me.normalGrid) {view=me.normalGrid.getView()}else{view=me.getView()}; view.el.select("tr:nth(1) td:nth(1)").elements[0].style["background-color"]="green";');
    JSCode('var view, me='#1'; if(me.normalGrid) {view=me.normalGrid.getView()}else{view=me.getView()}; view.el.select("tr:nth(1) td:nth(1)").elements[0].style["color"]="white";');
  end;
Link to comment
Share on other sites

Hi Delphi Developer,

 

  If I put some code to set the cell text before the two JSCode lines the cell colors appear correctly.

  with UniStringGrid1.JSInterface do
  begin
    UniStringGrid1.Cells[0,0] := 'test';

    JSCode('var view, me='#1'; if(me.normalGrid) {view=me.normalGrid.getView()}else{view=me.getView()}; view.el.select("tr:nth(1) td:nth(1)").elements[0].style["background-color"]="green";');
    JSCode('var view, me='#1'; if(me.normalGrid) {view=me.normalGrid.getView()}else{view=me.getView()}; view.el.select("tr:nth(1) td:nth(1)").elements[0].style["color"]="white";');
  end;

  If I put the line after the two JSCode  lines the cells don't have the colors applied.

 

  Is there a reason why the colors are not applied if the UniStringGrid1.Cells[0,0] := 'test'; is after the two JSCode lines?

Link to comment
Share on other sites

Hi,

 

One possible solution, try:

 

1. UniStringGrid1 -> ClientEvents -> UniEvents -> function beforeInit:

function beforeInit(sender, config)
{
    var me = sender;

    me.createStylesArray = function(rows) {
        var arr = [];
        for (var i = 0; i < rows; i++) {
            arr[i] = [];
        }
        return arr;
    };
}

2. UniStringGrid1 -> ClientEvents -> ExtEvents -> function reconfigure:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    var me = sender;
    for (i = me.fxCols; i < columns.length; i++) {
        columns[i].renderer = function(value, meta, record) {
            if (me.rc && me.rc[meta.rowIndex][meta.columnIndex + me.fxCols]) {
                meta.style = me.rc[meta.rowIndex][meta.columnIndex + me.fxCols];
            }
            return value;
        }
    };
}

3. MainForm -> OnReady:

procedure TMainForm.UniFormReady(Sender: TObject);
begin
  UniStringGrid1.JSInterface.JSCode('var me='#1'; me.rc=me.createStylesArray(me.store.count());');
end;

How to use, for example:

procedure TMainForm.UniFormReady(Sender: TObject);
begin
  UniStringGrid1.JSInterface.JSCode('var me='#1'; me.rc=me.createStylesArray(me.store.count());');
  UniStringGrid1.JSInterface.JSCode(#1'.rc[2][2]="background-color:green; color:white";'#1'.view.refresh();');
end;
procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniStringGrid1.JSInterface.JSCode(#1'.rc[1][1]="background-color:green; color:white";'#1'.view.refresh();');
end;
procedure TMainForm.UniButton2Click(Sender: TObject);
begin
  UniStringGrid1.JSInterface.JSCode(#1'.rc[1][1]="";'#1'.view.refresh();');
end;

Best regards,

Link to comment
Share on other sites

  • 1 month later...

Hi Delphi Developer,

 

  Is it possible to set up a column of cells (e.g. column 1) in a string grid so that when you click in a cell a TUniColorPalette is displayed underneath the cell, and once the user selects a

  color the cell background is set to this color?  I would also need to know what color was selected so I can store it in the cells object.

 

  The other question I have is how can I display a drop down combobox with some options in a cell and get the option that is selected so I can store it in a cell object?

Link to comment
Share on other sites

  • 2 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...