Make several columns hyperlink in a row where part of the hyperlink data coming form server in json

Make several columns hyperlink in a row where part of the hyperlink data coming form server in json

sam101sam101 Posts: 7Questions: 4Answers: 0
edited February 2016 in Free community support

Hi

I am populating a dataTable where data is coming form server as json.

... var aaData = filteredList.Select(d => new string[] { d.AgentID.ToString(), string.Format("{0:MM/dd/yyyy}", d.EnrollDate) , d.FirstName, d.LastName, d.UserName, d.Sponsor, d.NationalManager }).ToArray();
return Json(new
{
sEcho = Convert.ToInt32(incomingParameter.sEcho),
aaData = aaData,
iTotalRecords = Convert.ToInt32(totalRowCount),
iTotalDisplayRecords = Convert.ToInt32(filteredRowCount)
}, JsonRequestBehavior.AllowGet); ...

And my jquery is like following.

...$(document).ready(function () {
$('#agents').dataTable({
"bServerSide": true,
"sAjaxSource": "@Url.Action("NewPromotersQuery", "Admin")",
"bProcessing": true,
"type": "GET",
"sPaginationType": "full_numbers",
//"info": "true",
"sScrollX": "100%",
"deferRender": true,
"aoColumns": [
{ "sName": "Id" },
{ "sName": "Join Date" },
{"sName": "First Name" },
{ "sName": "Last Name" },
{ "sName": "Website" },
{ "sName": "Email" },
{ "sName": "Sponsor" },
{ "sName": "National" }
]
});
}); ...

Now i like to make the First Name and Last Name hyperlink where the link will be like "action/controller/the data coming as d.UserName ". Including this, the last column "National" will be the hyperlink as well which link will be "action/controller/d.NationalUserName". This d.NationalUserName will send inside json string but will not show in any grid Column.

Please help me to resolve this.

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    You should upgrade to the latest version of dataTables.

    Formatting your data as you want it to appear is one option.
    https://jsfiddle.net/glenderson/yg1w6gen/1/

    Using the .render() api is another option where you can format the data as the table is being loaded based upon the cell contents.

    Using the .rowCallback() api is another option where can you format the data as the rows are being generated.

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    See also the rendering section of the manual.

    Allan

This discussion has been closed.