Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hii to all,
I have done successfully,in getting the tables data from database & displayed in JQGrid.Now i want to add one more column to my JQGrid that should be an ActionLink say "EDIT",i.e i want to add a Link button to each row of my JQGrid,so that whenever user clicked on ActionLink it has to redirect to another View,and also it has to get the respective row data say some cell value(id)..This is my JQGrid

$("#emp-data-grid").jqGrid({
datatype: "local",
data: mdata,
colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email", "EDIT"],
colModel: [
{ name: "EmployeeID", index: "EmployeeID", sortable: false,
editable: true, edittype: 'checkbox', editoptions: { value: 'true:false' }
},
{ name: "EmpName", index: "EmpName" },
{ name: "Designation", index: "Designation" },
{ name: "Salary", index: "Salary", sorttype: "int" },
{ name: "MobileNo", index: "MobileNo", sorttype: "int" },
{ name: "Email", index: "Email" },
{ name: 'EditAction', formatter: 'showlink', formatoptions: { baseLinkUrl: '@Url.Action("Edit")'} },
],

shrinkToFit: true,
viewrecords: true,
sortorder: 'asc',
caption: "Employee List"
});

I have tried with the following but didn't get the Links column
name: 'EditAction', formatter: 'showlink', formatoptions: { baseLinkUrl: '@Url.Action("Edit")'} },

Please help me how can i show a links to each row..Thanks in advance

Thanks
Ramu
Posted

Add a column like below using custom formatter in jqGrid for adding actionlink
C#
{ name: 'LinkButton',
                         formatter: function (cellvalue, options, rowObject) {
                            var x =  '@Html.ActionLink( "Edit", "Action","Controller",new { requestId ="myId"  }, new {@style="color:Blue;font-weight:bold;"" })';
                             return x.replace("myId",rowObject[7]);
                         },sortable:false, align: 'left', width: 100
                     }



you can get row index value by using rowObject[columnindex].In this example i have also pass an id to the actionResult


Hope this helps
 
Share this answer
 
v2
Comments
Ram7 from Hyderabad 31-May-13 7:13am    
Dear Jameel,
Thanks for ur responce,the code u provided is working fine for my 1st requirement i.e displaying Edit Links to each row, but iam facing problem with getting an Id to the Controller Action.This is how i modified my JQGrid with ur code
$("#emp-data-grid").jqGrid({
datatype: "local",
data: mdata,
colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email", ""],
colModel: [
{ name: "EmployeeID", index: "EmployeeID", sortable: false,
editable: true, edittype: 'checkbox', editoptions: { value: 'true:false' }
},
{ name: "EmpName", index: "EmpName" },
{ name: "Designation", index: "Designation" },
{ name: "Salary", index: "Salary", sorttype: "int" },
{ name: "MobileNo", index: "MobileNo", sorttype: "int" },
{ name: "Email", index: "Email" },
{name: 'Link', formatter: function (cellvalue, options, rowObject) {
var x = '@Html.ActionLink("EDIT", "Edit", "Home", new { id = "EmployeeID" }, new { @style = "color:Blue;font-weight:bold;" })';
return x.replace("EmployeeID", rowObject[1]);
}, align: 'left', width: 100
}
shrinkToFit: true,
viewrecords: true,
sortorder: 'asc',
caption: "Employee List"
});
this is my Controller Action code:-
public ActionResult Edit(int id)
{
ViewData["RowData"] = int id;
return view();
}
In the above controller i want to access id and send to view for displaying that id in some textbox,using viewdata.
Please guide me where iam doing mistake,...
Thanks
Ramu
Jameel VM 31-May-13 7:29am    
can post this question as different thread? ofcourse i will help u
Ram7 from Hyderabad 3-Jun-13 1:19am    
Hi,i have posted as new thread,please help me.......
Jameel VM 3-Jun-13 1:24am    
where is the new question?
Ram7 from Hyderabad 3-Jun-13 1:35am    
This is the Question which i have updated now:-
"How to get an rows cell value from JQGrid to Controller Action method"
Thanks
Ramu
function displayButtons(cellvalue, options, rowObject) {
var x = '@Html.ActionLink( "Book", "PatientAppointment","DocAppTimeTable/",new { PatientID ="myId" },null)';
return x.replace("myId",rowObject['PatientId']);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900