How do I Display data from Controller inside a Column Render Function of jquery DataTable?











up vote
0
down vote

favorite












var CityListVM;
$(function () {



        CityListVM = {
dt: null,

init: function () {
dt = $('#Vendor-data-table').DataTable({
"serverSide": true,
"processing": true,
"ajax": {
"url": "@Url.Action("GetVendorList", "MgtVendor")",
"type": "POST",
"data": function (data) {

data.CustomerKey = $("#CustomerKey").val();
data.CustomerName = $("#CustomerName").val();
data.State = $("#State").val();
data.City = $("#City").val();
data.Attachments = $("#Attachments").val();
data.ZIP = $("#ZIP").val();
data.Phoneref = $("#Phoneref").val();
data.Phone = $("#Phone").val();
data.Email = $("#Email").val();
data.PrimaryContact = $("#PrimaryContact").val();
data.TradeList = $("#TradeList").val();
}
},
"columns": [

{
"title": "Vendor Name", "searchable": true, "sortable": true,
"render": function (data, type, full, meta) {
if (full.Attachments) return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a><img src="/Content/attachment-solid.png" height="10" />';
else return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a>';
}
},

{ "title": "State", "data": "State", "searchable": false, "sortable": false },

{ "title": "City", "data": "City", "searchable": false, "sortable": false },
{ "title": "ZIP", "data": "ZIP", "searchable": false, "sortable": false },
{
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},
{ "title": "Contact", "data": "PrimaryContact", "searchable": false, "sortable": false },
{
"title": "Phone", "searchable": false, "sortable": true,
"render": function (data, type, full, meta) {
return '<a class="btn btn-info" href="' + full.Phoneref + '">' + full.Phone +'</a>'; }
},

{
"title": "Control",
"data": "CustomerKey",
"searchable": false,
"sortable": false,
"render": function (data) {
return '<a href="@Url.Action("EditVendor", "MgtVendor")?id=' + data + '" class="btn">Edit</a> || <a href="@Url.Action("Delete", "MgtVendor")?id=' + data + '" class="btn">Deactivate</a>';
}
}
],
"lengthMenu": [[100, 50, 25, 10], [100, 50, 25, 10]],
});
},

refresh: function () {
dt.ajax.reload();
}
}
// Advanced Search Modal Search button click handler
$('#btnPerformAdvancedSearch').on("click", CityListVM.refresh);
// initialize the datatables
CityListVM.init();
});


The Part that I really need Help is:



                        {
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},









share|improve this question
























  • In the Render Part I need to DIsplay the value of the data returned from the function inside it which is coming as UNDEFINED.
    – user1744023
    Nov 7 at 19:21















up vote
0
down vote

favorite












var CityListVM;
$(function () {



        CityListVM = {
dt: null,

init: function () {
dt = $('#Vendor-data-table').DataTable({
"serverSide": true,
"processing": true,
"ajax": {
"url": "@Url.Action("GetVendorList", "MgtVendor")",
"type": "POST",
"data": function (data) {

data.CustomerKey = $("#CustomerKey").val();
data.CustomerName = $("#CustomerName").val();
data.State = $("#State").val();
data.City = $("#City").val();
data.Attachments = $("#Attachments").val();
data.ZIP = $("#ZIP").val();
data.Phoneref = $("#Phoneref").val();
data.Phone = $("#Phone").val();
data.Email = $("#Email").val();
data.PrimaryContact = $("#PrimaryContact").val();
data.TradeList = $("#TradeList").val();
}
},
"columns": [

{
"title": "Vendor Name", "searchable": true, "sortable": true,
"render": function (data, type, full, meta) {
if (full.Attachments) return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a><img src="/Content/attachment-solid.png" height="10" />';
else return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a>';
}
},

{ "title": "State", "data": "State", "searchable": false, "sortable": false },

{ "title": "City", "data": "City", "searchable": false, "sortable": false },
{ "title": "ZIP", "data": "ZIP", "searchable": false, "sortable": false },
{
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},
{ "title": "Contact", "data": "PrimaryContact", "searchable": false, "sortable": false },
{
"title": "Phone", "searchable": false, "sortable": true,
"render": function (data, type, full, meta) {
return '<a class="btn btn-info" href="' + full.Phoneref + '">' + full.Phone +'</a>'; }
},

{
"title": "Control",
"data": "CustomerKey",
"searchable": false,
"sortable": false,
"render": function (data) {
return '<a href="@Url.Action("EditVendor", "MgtVendor")?id=' + data + '" class="btn">Edit</a> || <a href="@Url.Action("Delete", "MgtVendor")?id=' + data + '" class="btn">Deactivate</a>';
}
}
],
"lengthMenu": [[100, 50, 25, 10], [100, 50, 25, 10]],
});
},

refresh: function () {
dt.ajax.reload();
}
}
// Advanced Search Modal Search button click handler
$('#btnPerformAdvancedSearch').on("click", CityListVM.refresh);
// initialize the datatables
CityListVM.init();
});


The Part that I really need Help is:



                        {
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},









share|improve this question
























  • In the Render Part I need to DIsplay the value of the data returned from the function inside it which is coming as UNDEFINED.
    – user1744023
    Nov 7 at 19:21













up vote
0
down vote

favorite









up vote
0
down vote

favorite











var CityListVM;
$(function () {



        CityListVM = {
dt: null,

init: function () {
dt = $('#Vendor-data-table').DataTable({
"serverSide": true,
"processing": true,
"ajax": {
"url": "@Url.Action("GetVendorList", "MgtVendor")",
"type": "POST",
"data": function (data) {

data.CustomerKey = $("#CustomerKey").val();
data.CustomerName = $("#CustomerName").val();
data.State = $("#State").val();
data.City = $("#City").val();
data.Attachments = $("#Attachments").val();
data.ZIP = $("#ZIP").val();
data.Phoneref = $("#Phoneref").val();
data.Phone = $("#Phone").val();
data.Email = $("#Email").val();
data.PrimaryContact = $("#PrimaryContact").val();
data.TradeList = $("#TradeList").val();
}
},
"columns": [

{
"title": "Vendor Name", "searchable": true, "sortable": true,
"render": function (data, type, full, meta) {
if (full.Attachments) return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a><img src="/Content/attachment-solid.png" height="10" />';
else return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a>';
}
},

{ "title": "State", "data": "State", "searchable": false, "sortable": false },

{ "title": "City", "data": "City", "searchable": false, "sortable": false },
{ "title": "ZIP", "data": "ZIP", "searchable": false, "sortable": false },
{
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},
{ "title": "Contact", "data": "PrimaryContact", "searchable": false, "sortable": false },
{
"title": "Phone", "searchable": false, "sortable": true,
"render": function (data, type, full, meta) {
return '<a class="btn btn-info" href="' + full.Phoneref + '">' + full.Phone +'</a>'; }
},

{
"title": "Control",
"data": "CustomerKey",
"searchable": false,
"sortable": false,
"render": function (data) {
return '<a href="@Url.Action("EditVendor", "MgtVendor")?id=' + data + '" class="btn">Edit</a> || <a href="@Url.Action("Delete", "MgtVendor")?id=' + data + '" class="btn">Deactivate</a>';
}
}
],
"lengthMenu": [[100, 50, 25, 10], [100, 50, 25, 10]],
});
},

refresh: function () {
dt.ajax.reload();
}
}
// Advanced Search Modal Search button click handler
$('#btnPerformAdvancedSearch').on("click", CityListVM.refresh);
// initialize the datatables
CityListVM.init();
});


The Part that I really need Help is:



                        {
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},









share|improve this question















var CityListVM;
$(function () {



        CityListVM = {
dt: null,

init: function () {
dt = $('#Vendor-data-table').DataTable({
"serverSide": true,
"processing": true,
"ajax": {
"url": "@Url.Action("GetVendorList", "MgtVendor")",
"type": "POST",
"data": function (data) {

data.CustomerKey = $("#CustomerKey").val();
data.CustomerName = $("#CustomerName").val();
data.State = $("#State").val();
data.City = $("#City").val();
data.Attachments = $("#Attachments").val();
data.ZIP = $("#ZIP").val();
data.Phoneref = $("#Phoneref").val();
data.Phone = $("#Phone").val();
data.Email = $("#Email").val();
data.PrimaryContact = $("#PrimaryContact").val();
data.TradeList = $("#TradeList").val();
}
},
"columns": [

{
"title": "Vendor Name", "searchable": true, "sortable": true,
"render": function (data, type, full, meta) {
if (full.Attachments) return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a><img src="/Content/attachment-solid.png" height="10" />';
else return '<a href="@Url.Action("Details", "MgtVendor")?id=' + full.CustomerKey + '" style="color:blue" target="_blank">' + full.CustomerName + '</a>';
}
},

{ "title": "State", "data": "State", "searchable": false, "sortable": false },

{ "title": "City", "data": "City", "searchable": false, "sortable": false },
{ "title": "ZIP", "data": "ZIP", "searchable": false, "sortable": false },
{
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},
{ "title": "Contact", "data": "PrimaryContact", "searchable": false, "sortable": false },
{
"title": "Phone", "searchable": false, "sortable": true,
"render": function (data, type, full, meta) {
return '<a class="btn btn-info" href="' + full.Phoneref + '">' + full.Phone +'</a>'; }
},

{
"title": "Control",
"data": "CustomerKey",
"searchable": false,
"sortable": false,
"render": function (data) {
return '<a href="@Url.Action("EditVendor", "MgtVendor")?id=' + data + '" class="btn">Edit</a> || <a href="@Url.Action("Delete", "MgtVendor")?id=' + data + '" class="btn">Deactivate</a>';
}
}
],
"lengthMenu": [[100, 50, 25, 10], [100, 50, 25, 10]],
});
},

refresh: function () {
dt.ajax.reload();
}
}
// Advanced Search Modal Search button click handler
$('#btnPerformAdvancedSearch').on("click", CityListVM.refresh);
// initialize the datatables
CityListVM.init();
});


The Part that I really need Help is:



                        {
"title": "Trades",
"searchable": true,
"data":"TradeList",
"sortable": false,
"render": function (data, type, full, meta) {
var as = null;
return full.TradeList=function () {
var urld = '@Url.Content("~/")' + "Utility/GetVendorTradeList";
$.getJSON(urld, { vendorkey: full.CustomerKey }, function (data1) {
return data1.val();
});
};
}
},






jquery razor model-view-controller datatables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 23:43









Gyrocode.com

35.9k868111




35.9k868111










asked Nov 7 at 19:19









user1744023

1324




1324












  • In the Render Part I need to DIsplay the value of the data returned from the function inside it which is coming as UNDEFINED.
    – user1744023
    Nov 7 at 19:21


















  • In the Render Part I need to DIsplay the value of the data returned from the function inside it which is coming as UNDEFINED.
    – user1744023
    Nov 7 at 19:21
















In the Render Part I need to DIsplay the value of the data returned from the function inside it which is coming as UNDEFINED.
– user1744023
Nov 7 at 19:21




In the Render Part I need to DIsplay the value of the data returned from the function inside it which is coming as UNDEFINED.
– user1744023
Nov 7 at 19:21

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53196338%2fhow-do-i-display-data-from-controller-inside-a-column-render-function-of-jquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53196338%2fhow-do-i-display-data-from-controller-inside-a-column-render-function-of-jquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini