How To Create a Dropdownlist for first column in table and dynamic bind the values from ajax respons
How To Create a Dropdownlist for first column in table and dynamic bind the values from ajax respons

First Requirement:
I'm Trying to create a Dropdownlist for first column inside datatable , and binding data from ajax response, but the ajax response got two , one object has list of values for dropdownlist column and the second object has remaining text field values.
Second Requirement:
whatever the selected values should go to the back end server along with other field values(Here I have to use Inline edit for the remaining fields).
Here is the code in MVC:
Controller Action method for ajax request:
.CSHTML file:
$(document).ready(function () {
var formatDate = function (value) {
if (value === null) return "";
var pattern = /Date\(([^)]+)\)/;
var results = pattern.exec(value);
if (results == null) return "";
var dt = new Date(parseFloat(results[1]));
return (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
}
var table = $("#PostMortemIRPTableId").DataTable({
"lengthChange": false,
"processing": true,
"serverProcessing": false,
"searching": true,
"footer": true,
"ajax":
{
"url": "/PostMortem/IRPTable",
"type": "GET",
"dataType": "JSON",
},
"columns": [
{
"data": "Issue",
},
{
"data": "IssueDescription",
},
{
"data": "ResolutionDescription",
},
{
"data": "PreventionDescription",
}
],
"columnDefs": [
{ "className": "dt-center", "targets": "_all" }
]
});
table.columns().iterator("column", function (ctx, idx) {
$(table.column(idx).header()).append("<span class=\"sort-icon\"/>");
});
public ActionResult IRPTable()
{
var IRPData = _postMortemService.GetIRPTable();
var CategoriesData = _postMortemService.GetCategories().Select(c => c.CategoryName + " : " + c.CategoryValue);
var FinalJson = new { IRPTableData = IRPData, IssuesList = CategoriesData };
try
{
return Json(new { data = FinalJson }, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
return Json(new { data = FinalJson }, JsonRequestBehavior.DenyGet);
}
}
Answers
Hi Sam462,
Thanks for your question. As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Thanks,
Sandy