markokas Posted December 5, 2013 Posted December 5, 2013 Hi all, Is it possible to change column index in the UniGrid runtime? Or How to change order of columns in the grid? example: grid.Columns[1].index:=5; br,mk. Quote
Sherzod Posted December 5, 2013 Posted December 5, 2013 Hi Marko Kastelic. Use this: grid.headerCt.move(oldColumnIndex, newColumnIndex); UniSession.AddJS(UniDBGrid1.JSName + '.headerCt.move(1,5);' + UniDBGrid1.JSName + '.view.refresh();'); Sincerely... 4 Quote
AlbertoVesx Posted November 21, 2014 Posted November 21, 2014 Hi, Where do we have to call unisession.AddJS? I mean, which event? Quote
Sherzod Posted November 21, 2014 Posted November 21, 2014 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. 1 Quote
marquesrb Posted December 21, 2015 Posted December 21, 2015 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 Quote
Sherzod Posted December 21, 2015 Posted December 21, 2015 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. 1 Quote
marquesrb Posted December 21, 2015 Posted December 21, 2015 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 Quote
Sherzod Posted December 21, 2015 Posted December 21, 2015 I'm sorry, need to analyze ... We will try to find a solution.. Best regards. 1 Quote
marquesrb Posted December 21, 2015 Posted December 21, 2015 Ty very much. A feature like "Grid.SaveColumnsOrder" and "Grid.LoadColumnsOrder" would be perfect lol Renato Marques Quote
Sherzod Posted December 21, 2015 Posted December 21, 2015 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. 1 Quote
marquesrb Posted December 21, 2015 Posted December 21, 2015 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 Quote
Ario.Paxaz Posted October 8, 2017 Posted October 8, 2017 * and still need to optimize the code Hi How to find AOldIndx, ANewIndx ,when user moved a column? Best Regards. Quote
Sherzod Posted October 8, 2017 Posted October 8, 2017 Hi, Can you clarify your question once again? Best regards, Quote
Ario.Paxaz Posted October 8, 2017 Posted October 8, 2017 Hi Suppose user moved a column. How to find AOldIndx, ANewIndx of column that moved by user ? Best Regards. Quote
Sherzod Posted October 8, 2017 Posted October 8, 2017 You can use this function for this: UniDBGrid -> ClientEvents -> ExtEvents -> function columnmove Quote
Ario.Paxaz Posted October 8, 2017 Posted October 8, 2017 Hi I see it,But how to can use it in Delphi in run time? I want use AOldIndx, ANewIndx. Best Regards. Quote
Sherzod Posted October 8, 2017 Posted October 8, 2017 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; Quote
SMARAM Posted April 8, 2020 Posted April 8, 2020 This doesn't work when dbgrid has a locked column. Any idea? Quote
Sherzod Posted April 8, 2020 Posted April 8, 2020 1 minute ago, SMARAM said: This doesn't work when dbgrid has a locked column. Hello, Which edition are you using? Can you please explain your case in more detail? Quote
SMARAM Posted April 8, 2020 Posted April 8, 2020 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 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.. I was trying to find the error in the ext-all file and the error occurred here, because it is empty Without a locked column, this works normally. Quote
Sherzod Posted April 8, 2020 Posted April 8, 2020 Can you please check it on the latest versions even without additional codes? Quote
picyka Posted July 27, 2021 Posted July 27, 2021 On 12/21/2015 at 2:47 PM, Sherzod said: 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. Is there already this code built into the grid currently? I get the error attached. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.