ZigZig Posted June 25, 2014 Share Posted June 25, 2014 Hi everybody, When using AddJS() to execute some JavaScript on client side, it seems that we can concatenate SomeComponent.JsName to a JS function: MyComponent.JsName+'.someFunction()', or directly use its Delphi name : 'MainForm.MyComponent.someFunction()' : UniSession.AddJS(SomeComponent.JSName+'.someFunction();'); UniSession.AddJS('MainForm.SomeComponent.someFunction();'); Ex : UniSession.AddJS(UniStringGrid1.JSName+'.store.suspendEvents();'); UniSession.AddJS('MainForm.UniStringGrid1.store.suspendEvents();'); Both seem to work perfectly. Is it right? What is the difference? Is there a best practice? Thanks a lot! Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted June 25, 2014 Administrators Share Posted June 25, 2014 It depends on you. Delphi names provides a more convenient way because it is more readable and easy to remember. Especially when you code in js client event screen. Link to comment Share on other sites More sharing options...
ZigZig Posted June 25, 2014 Author Share Posted June 25, 2014 Thank you Farshad! So, apart from my personal convenience, there is no difference? Link to comment Share on other sites More sharing options...
tappatappa Posted June 25, 2014 Share Posted June 25, 2014 I found that in some cases delphi name doesn't work. Maybe I am not using the Delphi name correctly, but here is my experience: recently I had to call some functions of the main form when as soon comes up, and I had to use its JSName, which I have found to be (unsurprisingly ) "O0" Here is an example Form1.toFront(); //doesn't work O0.toFront(); //its JSName, WORKS Also, you need to use the JSName when firing (client side) the Ajax events. Ajax=1&IsEvent=1&Obj=O0&Evt=activate&this=O0&_S_ID=zX4rfeDert67Gbe&_seq_=0 Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted June 25, 2014 Administrators Share Posted June 25, 2014 I found that in some cases delphi name doesn't work. Maybe I am not using the Delphi name correctly, but here is my experience: recently I had to call some functions of the main form when as soon comes up, and I had to use its JSName, which I have found to be (unsurprisingly ) "O0" Here is an example Form1.toFront(); //doesn't work O0.toFront(); //its JSName, WORKS Also, you need to use the JSName when firing (client side) the Ajax events. Ajax=1&IsEvent=1&Obj=O0&Evt=activate&this=O0&_S_ID=zX4rfeDert67Gbe&_seq_=0 Some components have sub components. For example: Form1.form Form1.window You can see this from ClientEvents dialog. Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted June 25, 2014 Administrators Share Posted June 25, 2014 Thank you Farshad! So, apart from my personal convenience, there is no difference? Technically there is no difference. Link to comment Share on other sites More sharing options...
M477H13U Posted January 30, 2018 Share Posted January 30, 2018 Hello everyones ! Does it mean we can call all js fonction by this way ? For instance : UniSession.AddJS(UniDBGrid1.JSName+'.cellModel.select();'); Link to comment Share on other sites More sharing options...
Sherzod Posted January 30, 2018 Share Posted January 30, 2018 Hi, If this is an acceptable method, then yes Link to comment Share on other sites More sharing options...
M477H13U Posted January 30, 2018 Share Posted January 30, 2018 I meant the ClientEvents functions !? Then, how do you pass parameters ? Could you give me an example with the method UniSession.AddJS(UniDBGrid1.JSName+'.cellModel.select();'); ? (: Link to comment Share on other sites More sharing options...
Sherzod Posted January 30, 2018 Share Posted January 30, 2018 I'm sorry, please explain a little more what you wanted Link to comment Share on other sites More sharing options...
M477H13U Posted January 30, 2018 Share Posted January 30, 2018 I meant, is it possible to launch 'ClientEvents ' fonctions inside of Delphi code by this way ? For instance, if I want to select a specific cell in a uniDBGrid, could I call the function as I wrote above ? If so, how can I pass parameters ? (is it more limpid now ? ) Link to comment Share on other sites More sharing options...
Sherzod Posted January 30, 2018 Share Posted January 30, 2018 Maybe you need to use like in this post ?!: http://forums.unigui.com/index.php?/topic/9171-dbgrid-cell-focus/&do=findComment&comment=47498 Link to comment Share on other sites More sharing options...
M477H13U Posted January 31, 2018 Share Posted January 31, 2018 I got two use case in my grid: Multiselection Option: After a grid refresh, I would like to keep the same selected row. But arrows are not controling movement anymore, you have to click first on grid body .... CellSelection Option: Same problem but different approach! First of all, how could I keep "focus" on my body grid (I actually got the focus as the onKeyDown event is fire, but arrows are not responding) and then retrieve selected row/cell ? Any workaround ? Link to comment Share on other sites More sharing options...
M477H13U Posted February 2, 2018 Share Posted February 2, 2018 Hello everyones! I manage to do what I want but I still have two question: Is the initialization of RecNo to 0 native on grid while refreshing the grid ? How could I override that in order to keep focus after a reconstruction of grid (in order to change grid options) or after grid refresh ? Link to comment Share on other sites More sharing options...
Sherzod Posted February 2, 2018 Share Posted February 2, 2018 Hi, Sorry, can you clarify your question once again ?! Link to comment Share on other sites More sharing options...
M477H13U Posted February 2, 2018 Share Posted February 2, 2018 No worries! (: The use case is as following: you're in a uniDBgrid with row 4 selected, and you apply a grid refresh. After the refresh, the row number 0 will constatnly be selected and previously selected row will be lost. How can I override this behavior ? Link to comment Share on other sites More sharing options...
Sherzod Posted February 2, 2018 Share Posted February 2, 2018 Hi, Well, you can try this solution, for example: 1. public { Public declarations } SavePlace: TBookmark; end; 2. UniDBGrid1 -> ClientEvents -> ExtEvents -> store.beforeload: function store.beforeload(store, operation, eOpts) { ajaxRequest(store.grid, '_beforeload', []) } 3. UniDBGrid1 -> OnAjaxEvent: procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_beforeload' then begin if Assigned(SavePlace) then UniDBGrid1.DataSource.DataSet.FreeBookmark(SavePlace); SavePlace := UniDBGrid1.DataSource.DataSet.GetBookmark end; end; 4. UniDBGrid1 -> OnAfterLoad: procedure TMainForm.UniDBGrid1AfterLoad(Sender: TUniDBGrid); begin Sender.DataSource.DataSet.GotoBookmark(SavePlace); end; Best regards, Link to comment Share on other sites More sharing options...
Sherzod Posted February 2, 2018 Share Posted February 2, 2018 But you need to think about pagination! Link to comment Share on other sites More sharing options...
M477H13U Posted February 2, 2018 Share Posted February 2, 2018 Okay, I will try your solution later and give you a feedback ! (: Link to comment Share on other sites More sharing options...
Sherzod Posted February 2, 2018 Share Posted February 2, 2018 Ok Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now