How to pass parameters to javascript function from .Action .Data method

1 Answer 95 Views
Grid
Patrick
Top achievements
Rank 1
Veteran
Patrick asked on 12 Jan 2022, 04:54 PM

I know how to call a client-side javascript function to get parameters to pass to the the controller for the various actions of a grid. But what if I need to call a javascript function that itself takes a parameter? How to I pass a value from the grid's action, data methods to the javascript function?

Thank you in advance for your advice.


//grid setup...

  .Create(update => update.Action("Add", "MyController).Data("GetParams"))
  .Update(update => update.Action("Update", "MyController").Data("GetParams"))
...

function GetParams(fSomeFlag) {
  var retVal;
  if (fSomeFlag = true)
    retVal = "someValForCreate";
  else
    retVal = "someValForUpdate";

    return {
        param1 : retVal,
        param2: "someOtherValue"
    };

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Jan 2022, 01:52 PM

Hello Patrick,

 

Thank you for writing to us.

It would be best if you get this fSomeFlag externally. Generally, you can use the $("#grid").data().kendoGrid.dataSource approach to get the instance of the grid and its datasource.

Can you share an example where this fSomeFlag value will come from? Then, I can send you a more precise and accurate solution.

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Patrick
Top achievements
Rank 1
Veteran
commented on 18 Jan 2022, 01:37 PM

Thank you for the reply, Eyup. I should have been more clear in the intent of fSomeFlag. I was hoping to reuse the javascript function GetParams for both the grid's Create and Update functions. So, I was hoping of being able to tell GetParams whether it was the Create method or Update method calling the function. So maybe the flag should have been fCalledByAdd: 


function GetParams(fCalledByAdd) {
  var retVal;
  if (fCalledByAdd = true)
    retVal = "someValForCreate";
  else
    retVal = "someValForUpdate";

    return {
        param1 : retVal,
        param2: "someOtherValue"
    };

Eyup
Telerik team
commented on 21 Jan 2022, 09:24 AM

Hi


Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Veteran
Answers by
Eyup
Telerik team
Share this question
or