Dynamically Add new column for Edit rows in data table asp.net c# 4.5
Dynamically Add new column for Edit rows in data table asp.net c# 4.5
nikunj_prajapati
Posts: 1Questions: 0Answers: 0
Hello,
I am newer in jquery datatable. I have bind a datatable using jqyery datatable. Now i want edit link on each row, I have used below code
[code]
Actions
Name
IsActive
CreatedOn
[/code]
[code]
$(document).ready(function () {
var grid = $('#grid').dataTable({
"bProcessing": true,
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "../AdminServices.asmx/GetCategories",
"fnServerData": function (sSource, aoData, fnCallback) {
var jsonAOData = JSON.stringify(aoData);
$.ajax({
//dataType: 'json',
contentType: "application/json; charset=utf-8",
type: "POST",
url: sSource,
data: "{jsonAOData : '" + jsonAOData + "'}",
success: function (msg) {
fnCallback(JSON.parse(msg.d));
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.responseText);
}
}
);
},
"aoColumnDefs": [
{
"fnRender": function (oObj) {
return "Edit";
},
"bSortable": false,
"aTargets": [0]
},
{
"sName": "Name",
"bSearchable": true,
"aTargets": [1]
},
{
"sName": "IsActive",
"bSearchable": true,
"bSortable": true,
"aTargets": [2]
},
{
"sName": "CreatedOn", "bSearchable": true,
"bSortable": true, "aTargets": [3]
}
]
});
grid.fnSetFilteringDelay(1000);
});
[/code]
[code]
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetCategories(string jsonAOData)
{
Enforce.That(string.IsNullOrEmpty(jsonAOData) == false,
"GetaData.GetTenants - jsonAOData can not be null");
CategoriesBL categoryBL = new CategoriesBL();
var jsonSerialiser = new JavaScriptSerializer();
var json = categoryBL.GetAllCategory().AsQueryable();
//var tenantRepository = new ;
//var tenants = tenantRepository.AsQueryable();
var dataTablePager = new DataTablePager(jsonAOData, json);
var formattedList = dataTablePager.Filter();
return JsonConvert.SerializeObject(formattedList);
}
[/code]
I am getting below response from web service
[code]
{"d":"{\"sEcho\":1,\"iTotalRecords\":8,\"iTotalDisplayRecords\":8,\"aaData\":[[\"1\",\"Beauty and Wellness\\r\\n\",\"True\",\"2/23/2014 11:44:42 AM\"],[\"2\",\"Leisure and Entertainment\\r\\n\",\"True\",\"2/23/2014 11:44:47 AM\"],[\"3\",\"Travel and Accommodation\\r\\n\",\"True\",\"2/23/2014 11:44:56 AM\"],[\"4\",\"Commerce\\r\\n\",\"True\",\"2/23/2014 11:45:02 AM\"],[\"5\",\"Services\\r\\n\",\"True\",\"2/23/2014 11:45:07 AM\"],[\"6\",\"Businesses\\r\\n\",\"False\",\"2/23/2014 11:45:11 AM\"],[\"7\",\"Health\\r\\n\",\"True\",\"2/23/2014 11:45:17 AM\"],[\"8\",\"Useful\\r\\n\",\"True\",\"2/23/2014 11:45:18 AM\"]],\"sColumns\":\"ID,,Name,,IsActive,,CreatedOn,\"}"}
[/code]
Issue is like when i am binding with datatable, its generating wired result
It generates some thing like below
[code]
Actions Name IsActive CreatedOn
Edit True undefined Beauty and Wellness undefined
Edit True undefined Leisure and Entertainment undefined
Edit True undefined Travel and Accommodation undefined
Edit True undefined Commerce undefined
Edit True undefined Services undefined
Edit False undefined Businesses undefined
Edit True undefined Health undefined
Edit True undefined Useful undefined
[/code]
Not sure why. Can you please help me at earliest?
Thanks,
Nik
I am newer in jquery datatable. I have bind a datatable using jqyery datatable. Now i want edit link on each row, I have used below code
[code]
Actions
Name
IsActive
CreatedOn
[/code]
[code]
$(document).ready(function () {
var grid = $('#grid').dataTable({
"bProcessing": true,
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "../AdminServices.asmx/GetCategories",
"fnServerData": function (sSource, aoData, fnCallback) {
var jsonAOData = JSON.stringify(aoData);
$.ajax({
//dataType: 'json',
contentType: "application/json; charset=utf-8",
type: "POST",
url: sSource,
data: "{jsonAOData : '" + jsonAOData + "'}",
success: function (msg) {
fnCallback(JSON.parse(msg.d));
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.responseText);
}
}
);
},
"aoColumnDefs": [
{
"fnRender": function (oObj) {
return "Edit";
},
"bSortable": false,
"aTargets": [0]
},
{
"sName": "Name",
"bSearchable": true,
"aTargets": [1]
},
{
"sName": "IsActive",
"bSearchable": true,
"bSortable": true,
"aTargets": [2]
},
{
"sName": "CreatedOn", "bSearchable": true,
"bSortable": true, "aTargets": [3]
}
]
});
grid.fnSetFilteringDelay(1000);
});
[/code]
[code]
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetCategories(string jsonAOData)
{
Enforce.That(string.IsNullOrEmpty(jsonAOData) == false,
"GetaData.GetTenants - jsonAOData can not be null");
CategoriesBL categoryBL = new CategoriesBL();
var jsonSerialiser = new JavaScriptSerializer();
var json = categoryBL.GetAllCategory().AsQueryable();
//var tenantRepository = new ;
//var tenants = tenantRepository.AsQueryable();
var dataTablePager = new DataTablePager(jsonAOData, json);
var formattedList = dataTablePager.Filter();
return JsonConvert.SerializeObject(formattedList);
}
[/code]
I am getting below response from web service
[code]
{"d":"{\"sEcho\":1,\"iTotalRecords\":8,\"iTotalDisplayRecords\":8,\"aaData\":[[\"1\",\"Beauty and Wellness\\r\\n\",\"True\",\"2/23/2014 11:44:42 AM\"],[\"2\",\"Leisure and Entertainment\\r\\n\",\"True\",\"2/23/2014 11:44:47 AM\"],[\"3\",\"Travel and Accommodation\\r\\n\",\"True\",\"2/23/2014 11:44:56 AM\"],[\"4\",\"Commerce\\r\\n\",\"True\",\"2/23/2014 11:45:02 AM\"],[\"5\",\"Services\\r\\n\",\"True\",\"2/23/2014 11:45:07 AM\"],[\"6\",\"Businesses\\r\\n\",\"False\",\"2/23/2014 11:45:11 AM\"],[\"7\",\"Health\\r\\n\",\"True\",\"2/23/2014 11:45:17 AM\"],[\"8\",\"Useful\\r\\n\",\"True\",\"2/23/2014 11:45:18 AM\"]],\"sColumns\":\"ID,,Name,,IsActive,,CreatedOn,\"}"}
[/code]
Issue is like when i am binding with datatable, its generating wired result
It generates some thing like below
[code]
Actions Name IsActive CreatedOn
Edit True undefined Beauty and Wellness undefined
Edit True undefined Leisure and Entertainment undefined
Edit True undefined Travel and Accommodation undefined
Edit True undefined Commerce undefined
Edit True undefined Services undefined
Edit False undefined Businesses undefined
Edit True undefined Health undefined
Edit True undefined Useful undefined
[/code]
Not sure why. Can you please help me at earliest?
Thanks,
Nik
This discussion has been closed.