jQGrid Radio Button Issue-ASP.NET MVC3

Posted by Sheetal.Swamy under jQuery on 7/8/2011 | Points: 10 | Views : 6425 | Status : [Member] | Replies : 1
I am using JQGrid with two radio button columns

{ name: 'Primary', index: 'Primary', width: 60, align: 'left', formatter: RadioPrimary },
{ name: 'Secondary', index: 'Secondary', width: 60, align: 'left', formatter: RadioSecondary }

and the Radio buttons are defined as below:

function RadioSecondary() {
return "<input type=radio name=rbtn id=rbtnSecondary />";

function RadioPrimary() {
return "<input type=radio name=rbtn id=rbtnPrimary />";

My requirement is : In each row, i have to select either Primary or Secondary Radio button.

My Problem is:
1. If i dont specify the name attribute, i am not able to select Radiobutton.
2. If i specify the same name to both Radiobuttons, then it is allowing to select only 1 Radiobutton (out of many rows)
3. If i give different names to Primary and Secondary radiobuttons, the GroupName concept is applying columnwise. I.e i can select only one Primary radiobutton and 1 Secondary Radiobutton

Please let me know how to solve this issue..


Posted by: Sheetal.Swamy on: 7/8/2011 [Member] Starter | Points: 25

The solution to this is as below.

We need to add the name to radio buttons in controller while getting the json data (i.e before loading the JQGrid)
var jsonData = new
total = totalPages,
records = griddataContext.RMSUsers.Count(),
rows = (
from user in usernameLists
select new
i = user.ID,
cell = new string[] { user.ID.ToString(), user.FirstName, user.EmailID,
"<input type=\"radio\" id=\"btnPrimary\" name=\"" + user.ID + "\" />", "<input type=\"radio\" id=\"btnSecondary\" name=\"" + user.ID + "\" />"}

and in JQGrid colModel:
{ name: 'Primary', name: 'Primary', index: 'Primary', editable: true, edittype: 'custom', width: 100},
{ name: 'Secondary', name: 'Secondary', index: 'Secondary', editable: true, edittype: 'custom', width: 100},

This will create 2 radiobutton columns with same name in each row.. So that we can select only 1 radio button per row.

Sheetal. B. Swamy

Sheetal.Swamy, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response