PDA

View Full Version : [CLOSED] Custom parameter in grid column Renderer



alscg
Dec 12, 2013, 12:41 PM
Hi,

We are creating a grid using dynamic columns from controller.

I need to pass custom parameters(string[]) in grid column Renderer which would call RowActionBtnState() method from external JS file.

Controller :


string[] userRoles = new string[] { "role1", ""role2", "role3" };

columns.Insert(0, new Column() { Text = "", DataIndex = "State_ID", Locked = true, Width = 40, Renderer = new Renderer() { Fn = "RowActionBtnState", FormatArgs = userRoles } });


JS file code :


var RowActionBtnState = function (value, meta, record, index, userRoles) {
// Some Code
};


When I set a debugger inside RowActionBtnState() the userRoles parameter shows 1 everytime.

Please suggest.

Daniil
Dec 12, 2013, 3:12 PM
Hi @alscg,

You should use Handler instead of Fn.

Handler = "return RowActionBtnState(value, metadata, record, rowIndex, 'userRoles');"

alscg
Dec 13, 2013, 11:15 AM
Hi @alscg,

You should use Handler instead of Fn.

Handler = "return RowActionBtnState(value, metadata, record, rowIndex, 'userRoles');"

Daniil,

Handler is working but the parameter 'userRoles' that i need to pass is an array of string as i mentioned in Controller section of previous post.

Do we have any way to pass it to the function in JS file?

Daniil
Dec 13, 2013, 11:59 AM
Well, I used 'userRoles' as an example. You have to replace it with your real userRoles array.

alscg
Dec 13, 2013, 12:55 PM
Well, I used 'userRoles' as an example. You have to replace it with your real userRoles array.

Yes. I have already tried with concatenation as below :
Controller :


string[] userRoles = new string[] { "role1", ""role2", "role3" };

columns.Insert(0, new Column() { Text = "", DataIndex = "State_ID", Locked = true, Width = 40, Renderer = new Renderer() { Handler = "return RowActionBtnState(value, metadata, record, rowIndex, '" + userRoles + "');" } });


But in JS function i am receiving parameter value as "System.String[]".

Baidaly
Dec 13, 2013, 8:31 PM
Hello!

You need to serialize these values:


string[] userRoles = new string[] { "role1", ""role2", "role3" };

columns.Insert(0, new Column() { Text = "", DataIndex = "State_ID", Locked = true, Width = 40, Renderer = new Renderer() { Handler = "return RowActionBtnState(value, metadata, record, rowIndex, '" + JSON.Serialize(userRoles)+ "');" } });

alscg
Dec 16, 2013, 4:01 AM
It worked.

Thank you Baidaly.