Jump to content
uniGUI Discussion Forums
Sign in to follow this  
mos

StringGrid Questions

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Bumping this one again.

 

Any further updates on the items above specifically item 1 and 4?

Share this post


Link to post
Share on other sites

Hi,

 

Bumping this one again.

 

Any further updates on the items above specifically item 1 and 4?

 

Do you use FixedCols ?!

Share this post


Link to post
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,

Share this post


Link to post
Share on other sites

Hi Delphi Developer,

 

  I seem to be getting some sort of Ajax error.

 

  See attached screenshot.

post-5257-0-21258500-1513208469_thumb.png

Share this post


Link to post
Share on other sites

Hi,

 

Hi Delphi Developer,

 

  I seem to be getting some sort of Ajax error.

 

  See attached screenshot.

 

If it's not difficult for you, please make a test case

Share this post


Link to post
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;

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Hi Delphi Developer,

 

  I tried to create a TUniStringGrid in code and then used the JSCode lines you gave me but I get an Ajax Error.

 

  I have attached a sample test case.

StringGrid2.zip

Share this post


Link to post
Share on other sites

Hi Delphi Developer,

 

  Still waiting for some sort of update.

Share this post


Link to post
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,

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Hi Delphi Developer,

 

  Any help with the above two items would be appreciated.

Share this post


Link to post
Share on other sites

Hi,

 

Ok, I will try to analyze your requests,

 

Which build are you using?

Share this post


Link to post
Share on other sites

Hi Delphi Developer,

 

  Build 1413.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×