Jump to content

UniDbGrid columns, change index


Recommended Posts

  • 11 months later...

Hi,

 

Where do we have to call unisession.AddJS? I mean, which event?

 

Hi,

 

For example:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS(UniDBGrid1.JSName + '.headerCt.move(1,5);' + UniDBGrid1.JSName + '.view.refresh();');
end;

Best regards.

  • Upvote 1
Link to post
Share on other sites
  • 1 year later...

Delphi Developer, please, let's see if you can help me...

 

I'm planning to create some configurations where the user can choose the order of the columns.

 

Ex:

 

Orginal order:

Column A (idx 0), Column B (idx 1), Column C (idx 2), Column D (idx 3)

 

Reorganized order:

Column C (idx 0), Column A (idx 1), Column D (idx 2), Column B (idx 3)

 

 

Using the technique above (.headerCt.move()) if I move the column 1 to 3 and 3 to 5, the result is moving column 1 to 5, which I don't want to.

Is there a way to do what I want?

 

 

Renato Marques

Link to post
Share on other sites

Hi,

 

Sorry, maybe I did not quite understand your question,
but try, for your case:

 

Orginal order:

Column A (idx 0), Column B (idx 1), Column C (idx 2), Column D (idx 3)

 

Reorganized order:

Column C (idx 0), Column A (idx 1), Column D (idx 2), Column B (idx 3)

headerCt.move(1,3);
headerCt.move(0,1);

Best regards.

  • Upvote 1
Link to post
Share on other sites

Hi,

 

Sorry, the example is not my real case.

 

I figured out that headerCt.move() will not help me in this case because I can reorder all the columns and, in the end, some columns would be scrambled.

Is there any other feature to move columns order?

 

 

Ty

 

Renato Marques

Link to post
Share on other sites

Hi,

 

Sorry again,
If I correctly understood you, in fact you want to swap "two" columns..

Then try:

uses ..., Math;

procedure TMainForm.UniButton1Click(Sender: TObject);
  
  procedure _move(AUniGrid: TUniDBGrid; AOldIndx, ANewIndx: Integer);
  var
    maxIndx, minIndx: Integer;
  begin
    if AUniGrid.Columns.Count < 2 then Exit;
    // also need check values AOldIndx, ANewIndx for correctness

    if Abs(AOldIndx - ANewIndx) > 1 then
    begin
      maxIndx := Max(AOldIndx, ANewIndx);
      minIndx := Min(AOldIndx, ANewIndx);
      UniSession.AddJS(AUniGrid.JSName + '.headerCt.move('+IntToStr(minIndx)+','+IntToStr(maxIndx)+');');
      UniSession.AddJS(AUniGrid.JSName + '.headerCt.move('+IntToStr(maxIndx - 1)+','+IntToStr(minIndx)+');');
    end
    else
    begin
      UniSession.AddJS(AUniGrid.JSName + '.headerCt.move('+IntToStr(AOldIndx)+','+IntToStr(ANewIndx)+');');
    end;
    UniSession.AddJS(AUniGrid.JSName + '.view.refresh();');
  end;

begin
  _move(UniDBGrid1, 3, 1);
end;

* and still need to optimize the code :)

 

Best regards.

  • Upvote 1
Link to post
Share on other sites

Hi.

 

In fact I need to to swap "n" columns.

 

I set this:

 

UniDBGrid1 -> ClentsEvents -> UniEvents ... add beforeInit

 

function beforeInit(sender, config){
  config.enableColumnMove = true
}

 

 

That allows me to swap every column to any order I want. Then I would like to save these positions and load them further.

But when I swap the column, the property "Column[X].Index" still is "X" (old position) and not the "new X" (new position).

 

Sorry if I'm not explaining it well, and thanks for your help.

 

 

Renato Marques

Link to post
Share on other sites
  • 1 year later...

Can you try this ?:

 

1.

function columnmove(ct, column, fromIdx, toIdx, eOpts)
{
    ajaxRequest(this, 'columnMoved', ["oldIndx="+fromIdx, "newIndx="+toIdx]);
}

2.

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = 'columnMoved' then
  begin
    ShowMessage(Params.Values['oldIndx'] + ', ' + Params.Values['newIndx']);
  end;
end;
Link to post
Share on other sites
  • 2 years later...
1 hour ago, Sherzod said:

Hello,

Which edition are you using?

Can you please explain your case in more detail?

Hi Sherzod.

Version:1.0.0.1416

locked.png.b8564eb65bc49edc4777db994aaee2af.png

When the unidbgrid has a column locked, this code doens't work

UniSession.AddJS(UniDBGrid1.JSName + '.headerCt.move(1,5);' + UniDBGrid1.JSName + '.view.refresh();');

This error is displayed..

jserror.thumb.png.f1cd23ad0118f124148fe43a31183f2f.png

I was trying to find the error in the ext-all file and the error occurred here, because it is empty

move.png.70e4df42b64021b7c358afd15c3f4cce.png

Without a locked column, this works normally.

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

×
×
  • Create New...