Answered by:
Bootstrap datatables issue column not found

Question
-
User-183185495 posted
I am using bootstrap datatables.net and I am getting an error even though it says the column is their i have tried all variations of the column but none work. The data is their as in the example json ! Btw CreatedDate is just
<script> $(document).ready(function () { $("#audTrailTable").DataTable({ "ajax": { url: "/MISObjects/GetAuditTrailData/", type: "get", database: "json" }, "columns": [ { "data": "CreatedDate" }, { "data": "createdby" }, { "data": "action" } ], "scrollY": "200px", "scrollCollapse": true, "paging": false, "processing": true, // for show progress bar "filter": true, // this is for disable filter (search box) "orderMulti": false // for disable multiple column at once }) }); </script>
Json Example The First Column is the Action the user done the second date it was performed on and by whom I only need those three in the grid.
"Created Case","CreatedDate":"2020-07-28T20:59:54.2791487+01:00","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":5,"IPAddressBytes":"","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":0,"MISObjectId":7,"Action":"David did some tests"
[HttpGet] public IActionResult GetAuditTrailData() { int test = 7; var auditTrailsHistory = _context.MisAuditTrail.Where(w => w.isActive == true && w.isDeleted == false && w.MISObjectId==test).ToList(); string output = JsonConvert.SerializeObject(auditTrailsHistory); var testObject = Json(new { data = auditTrailsHistory }); return Json(new { data = auditTrailsHistory }); }
Error
Also as I am calling this using AJax I store my case id in TempData but i cant access temp data here as it always seems to be empty whats my best way of passing the case Id which is TempData.Peek["CaseId"] INTO the ajax call
Ps I really wish Microsoft introduced mark down for images ! in this forum.
Full json being returned by functon
[{"AuditTrailType":0,"Id":4,"IPAddressBytes":"","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":0,"MISObjectId":7,"Action":"Created Case","CreatedDate":"2020-07-28T20:59:54.2791487","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":5,"IPAddressBytes":"","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":0,"MISObjectId":7,"Action":"David did some tests","CreatedDate":"2020-07-28T21:10:50.4330446","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":7,"IPAddressBytes":"","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":0,"MISObjectId":7,"Action":"This should be the notes","CreatedDate":"2020-07-28T21:15:20.6188206","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":11,"IPAddressBytes":"","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":0,"MISObjectId":7,"Action":"PoI Created MatsMITH","CreatedDate":"2020-07-28T21:39:31.3641723","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":17,"IPAddressBytes":"","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":0,"MISObjectId":7,"Action":"Vessel Created Dill Bar","CreatedDate":"2020-07-29T22:47:04.4783467","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":125,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":8,"MISObjectId":7,"Action":"File was Uploaded None","CreatedDate":"2020-08-01T23:35:26.8397511","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":126,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":8,"MISObjectId":7,"Action":"File was Uploaded None","CreatedDate":"2020-08-01T23:35:26.8946256","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":127,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":8,"MISObjectId":7,"Action":"File was Uploaded None","CreatedDate":"2020-08-01T23:35:26.9072356","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":128,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":8,"MISObjectId":7,"Action":"File was Uploaded None","CreatedDate":"2020-08-01T23:35:26.9155553","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":129,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":8,"MISObjectId":7,"Action":"File was Uploaded None","CreatedDate":"2020-08-01T23:35:26.9210784","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":130,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9268297","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":131,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9320819","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":132,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9377364","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":133,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9430705","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":134,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9484449","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":135,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9544294","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":136,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9607799","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":137,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9882178","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":138,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:26.9961234","CreatedBy":"David","isActive":true,"isDeleted":false},{"AuditTrailType":0,"Id":139,"IPAddressBytes":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000Ā","TennantId":"92b4ebe2-c81e-4fbf-91d0-9b422a7843c4","AuditType":5,"MISObjectId":7,"Action":"File was Uploaded PDF","CreatedDate":"2020-08-01T23:35:27.0031033","CreatedBy":"David","isActive":true,"isDeleted":false}]
Sunday, August 2, 2020 4:43 PM
Answers
-
User475983607 posted
The error message is telling you that something is wrong with the first column. I assume it is the column name.
"columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ],
I built a test based on your code and it functions as expected.
public class DataTableWrapper<T> { public T data { get; set; } } public class MISAuditTrail { public enum AudItTypes { [Display(Name = "Microsoft Word")] Word = 1, [Display(Name = "Microsoft Excel")] Excel = 2, [Display(Name = "Image")] Image = 3, [Display(Name = "Voice Recordings")] Voice = 4, [Display(Name = "PDF")] PDF = 5, [Display(Name = "Video")] Video = 6, [Display(Name = "Evidence")] Evidence = 7, [Display(Name = "None")] None = 8, [Display(Name = "Notes")] NOTES = 9, [Display(Name = "Shared Case")] SharedCase = 10, [Display(Name = "Created Case")] CreatedCase = 11, } public AudItTypes AuditTrailType { get; set; } public int Id { get; set; } [StringLength(30)] public string IPAddressBytes { get; set; } public Guid TennantId { get; set; } public int AuditType { get; set; } public int MISObjectId { get; set; } [Required] public string Action { get; set; } public DateTime CreatedDate { get; set; } [StringLength(30)] public string CreatedBy { get; set; } public bool isActive { get; set; } public bool isDeleted { get; set; } }
@{ ViewData["Title"] = "Index"; } <h1>Index</h1> <table id="audTrailTable"> <thead> <tr> <th>CreatedDate</th> <th>createdby</th> <th>action</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> <td></td> </tr> </tbody> </table> @section scripts { <script> $(document).ready(function () { $("#audTrailTable").DataTable({ "ajax": { url: "/DataTable/GetAuditTrailData/", type: "get", database: "json" }, "columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ], "scrollY": "200px", "scrollCollapse": true, "paging": false, "processing": true, // for show progress bar "filter": true, // this is for disable filter (search box) "orderMulti": false // for disable multiple column at once }) }); </script> }
public class DataTableController : Controller { public IActionResult Index() { return View(); } [HttpGet] public ActionResult<DataTableWrapper<List<MISAuditTrail>>> GetAuditTrailData() { DataTableWrapper<List<MISAuditTrail>> data = new DataTableWrapper<List<MISAuditTrail>>() { data = PopulateTestData() }; return data; } public List<MISAuditTrail> PopulateTestData() { List<MISAuditTrail> list = new List<MISAuditTrail>() { new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, }; return list; } }
In the future, please share code that the community can actually run. Take the time to create test data for us to hep you. Frankly, testing should be a part of your development process.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 3, 2020 5:50 PM
All replies
-
User-1330468790 posted
Hi roguenidb,
You could read the error message in below format:
DataTables warning: table id={id}- Requested unknown parameter '{parameter}' for row '{row-index}', column '{column-index}'
Where:
{id}
is replaced with the DOM id of the table that has triggered the error{parameter}
is the name of the data parameter DataTables is requesting{row-index}
is the DataTables internal row index (row().index()
) for the row that has triggered the error.{column-index}
is the column data index (column().index()
) for the column that has triggered the error. The column index information was added in DataTables 1.10.10.
Therefore, the problem is located in the data matching.
JavaScript is a case-sensitive language. This means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. Could you please check if you set the data key name with the consistent capitalization of letters for every data column? For example, you set the column key with the string "createddate" but pass the value with the string "CreatedDate". (Though you provide the codes with "CreatedDate" but the errors tells you might use "createddate")
Another possible reason is that you have not passed the values correctly from server side. If it is fact, could you please share the model "MisAuditTrail" so that we will be able to target the problem.
Hope this can help you.
Best regards,
Sean
Monday, August 3, 2020 2:47 AM -
User-474980206 posted
You should use the browsers network debugger to see the actual response.
Monday, August 3, 2020 1:58 PM -
User-183185495 posted
Hi Please see below I tried both versions CreatedDate and createddate no different
public class MISAuditTrail { public enum AudItTypes { [Display(Name = "Microsoft Word")] Word = 1, [Display(Name = "Microsoft Excel")] Excel = 2, [Display(Name = "Image")] Image = 3, [Display(Name = "Voice Recordings")] Voice = 4, [Display(Name = "PDF")] PDF = 5, [Display(Name = "Video")] Video = 6, [Display(Name = "Evidence")] Evidence = 7, [Display(Name = "None")] None = 8, [Display(Name = "Notes")] NOTES = 9, [Display(Name = "Shared Case")] SharedCase = 10, [Display(Name = "Created Case")] CreatedCase= 11, } public AudItTypes AuditTrailType { get; set; } public int Id { get; set; } [StringLength(30)] public string IPAddressBytes { get; set; } public Guid TennantId { get; set; } public int AuditType { get; set; } public int MISObjectId { get; set; } [Required] public string Action { get; set; } public DateTime CreatedDate { get; set; } [StringLength(30)] public string CreatedBy { get; set; } public bool isActive { get; set; } public bool isDeleted { get; set; } }
Sean Fang
Hi roguenidb,
You could read the error message in below format:
DataTables warning: table id={id}- Requested unknown parameter '{parameter}' for row '{row-index}', column '{column-index}'
Where:
{id}
is replaced with the DOM id of the table that has triggered the error{parameter}
is the name of the data parameter DataTables is requesting{row-index}
is the DataTables internal row index (row().index()
) for the row that has triggered the error.{column-index}
is the column data index (column().index()
) for the column that has triggered the error. The column index information was added in DataTables 1.10.10.
Therefore, the problem is located in the data matching.
JavaScript is a case-sensitive language. This means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. Could you please check if you set the data key name with the consistent capitalization of letters for every data column? For example, you set the column key with the string "createddate" but pass the value with the string "CreatedDate". (Though you provide the codes with "CreatedDate" but the errors tells you might use "createddate")
Another possible reason is that you have not passed the values correctly from server side. If it is fact, could you please share the model "MisAuditTrail" so that we will be able to target the problem.
Hope this can help you.
Best regards,
Sean
Monday, August 3, 2020 4:20 PM -
User-183185495 posted
No errors the browser console
You should use the browsers network debugger to see the actual response.
Monday, August 3, 2020 4:57 PM -
User475983607 posted
The error message is telling you that something is wrong with the first column. I assume it is the column name.
"columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ],
I built a test based on your code and it functions as expected.
public class DataTableWrapper<T> { public T data { get; set; } } public class MISAuditTrail { public enum AudItTypes { [Display(Name = "Microsoft Word")] Word = 1, [Display(Name = "Microsoft Excel")] Excel = 2, [Display(Name = "Image")] Image = 3, [Display(Name = "Voice Recordings")] Voice = 4, [Display(Name = "PDF")] PDF = 5, [Display(Name = "Video")] Video = 6, [Display(Name = "Evidence")] Evidence = 7, [Display(Name = "None")] None = 8, [Display(Name = "Notes")] NOTES = 9, [Display(Name = "Shared Case")] SharedCase = 10, [Display(Name = "Created Case")] CreatedCase = 11, } public AudItTypes AuditTrailType { get; set; } public int Id { get; set; } [StringLength(30)] public string IPAddressBytes { get; set; } public Guid TennantId { get; set; } public int AuditType { get; set; } public int MISObjectId { get; set; } [Required] public string Action { get; set; } public DateTime CreatedDate { get; set; } [StringLength(30)] public string CreatedBy { get; set; } public bool isActive { get; set; } public bool isDeleted { get; set; } }
@{ ViewData["Title"] = "Index"; } <h1>Index</h1> <table id="audTrailTable"> <thead> <tr> <th>CreatedDate</th> <th>createdby</th> <th>action</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> <td></td> </tr> </tbody> </table> @section scripts { <script> $(document).ready(function () { $("#audTrailTable").DataTable({ "ajax": { url: "/DataTable/GetAuditTrailData/", type: "get", database: "json" }, "columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ], "scrollY": "200px", "scrollCollapse": true, "paging": false, "processing": true, // for show progress bar "filter": true, // this is for disable filter (search box) "orderMulti": false // for disable multiple column at once }) }); </script> }
public class DataTableController : Controller { public IActionResult Index() { return View(); } [HttpGet] public ActionResult<DataTableWrapper<List<MISAuditTrail>>> GetAuditTrailData() { DataTableWrapper<List<MISAuditTrail>> data = new DataTableWrapper<List<MISAuditTrail>>() { data = PopulateTestData() }; return data; } public List<MISAuditTrail> PopulateTestData() { List<MISAuditTrail> list = new List<MISAuditTrail>() { new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, }; return list; } }
In the future, please share code that the community can actually run. Take the time to create test data for us to hep you. Frankly, testing should be a part of your development process.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 3, 2020 5:50 PM -
User-183185495 posted
Do u have a paypal donate page mate at all you sir are a legend have seen you for years on here thank you it was the way I was returning it in my method that was the issue. Got it working thanks so much.
The error message is telling you that something is wring with the first column. I assume it is the column name.
"columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ],
I built a test based on your code and it functions as expected.
public class DataTableWrapper<T> { public T data { get; set; } } public class MISAuditTrail { public enum AudItTypes { [Display(Name = "Microsoft Word")] Word = 1, [Display(Name = "Microsoft Excel")] Excel = 2, [Display(Name = "Image")] Image = 3, [Display(Name = "Voice Recordings")] Voice = 4, [Display(Name = "PDF")] PDF = 5, [Display(Name = "Video")] Video = 6, [Display(Name = "Evidence")] Evidence = 7, [Display(Name = "None")] None = 8, [Display(Name = "Notes")] NOTES = 9, [Display(Name = "Shared Case")] SharedCase = 10, [Display(Name = "Created Case")] CreatedCase = 11, } public AudItTypes AuditTrailType { get; set; } public int Id { get; set; } [StringLength(30)] public string IPAddressBytes { get; set; } public Guid TennantId { get; set; } public int AuditType { get; set; } public int MISObjectId { get; set; } [Required] public string Action { get; set; } public DateTime CreatedDate { get; set; } [StringLength(30)] public string CreatedBy { get; set; } public bool isActive { get; set; } public bool isDeleted { get; set; } }
@{ ViewData["Title"] = "Index"; } <h1>Index</h1> <table id="audTrailTable"> <thead> <tr> <th>CreatedDate</th> <th>createdby</th> <th>action</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> <td></td> </tr> </tbody> </table> @section scripts { <script> $(document).ready(function () { $("#audTrailTable").DataTable({ "ajax": { url: "/DataTable/GetAuditTrailData/", type: "get", database: "json" }, "columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ], "scrollY": "200px", "scrollCollapse": true, "paging": false, "processing": true, // for show progress bar "filter": true, // this is for disable filter (search box) "orderMulti": false // for disable multiple column at once }) }); </script> }
public class DataTableController : Controller { public IActionResult Index() { return View(); } [HttpGet] public ActionResult<DataTableWrapper<List<MISAuditTrail>>> GetAuditTrailData() { DataTableWrapper<List<MISAuditTrail>> data = new DataTableWrapper<List<MISAuditTrail>>() { data = PopulateTestData() }; return data; } public List<MISAuditTrail> PopulateTestData() { List<MISAuditTrail> list = new List<MISAuditTrail>() { new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, }; return list; } }
In the future, please share code that the community can actually run. Take the time to create test data for us to hep you. Frankly, testing should be a part of your development process.
Monday, August 3, 2020 6:40 PM -
User-183185495 posted
Tell me I am storing TempData CaseId I need to pass it to the query but as I have
Int32.TryParse(TempData.Peek("CaseId").ToString(), out int resultCaseId);
Which should go the link query in my GetAuditTrail but when I do the result of TempData.Peek is not set yet as I have not hit the index view yet in this case cause the ajax get is being hit first. Out Do I get the case id value properly into the auditrailfunction
For Example I set TempData here but ajax call cannot see that.
Btw this grid is inside a view component and I am invoking as such.
<div>@await Component.InvokeAsync("AudiTrailList", new { caseId = Model.Id })</div>
// GET: MISObjects/Edit/5 public async Task<IActionResult> Edit(int id) { if (id == null) { return NotFound(); } SetupViewBags(); var list = _userManager.Users.ToListAsync(); ViewBag.Users = list; var mISObject = await _context.MISobject.FindAsync(id); HttpContext.Session.SetString("CaseId", id.ToString()); TempData["CaseId"] = id.ToString(); SetupUploadsViewBags(); CaseId = id; if (mISObject == null) { return NotFound(); } return View(mISObject); }
mgebhard
The error message is telling you that something is wring with the first column. I assume it is the column name.
"columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ],
I built a test based on your code and it functions as expected.
public class DataTableWrapper<T> { public T data { get; set; } } public class MISAuditTrail { public enum AudItTypes { [Display(Name = "Microsoft Word")] Word = 1, [Display(Name = "Microsoft Excel")] Excel = 2, [Display(Name = "Image")] Image = 3, [Display(Name = "Voice Recordings")] Voice = 4, [Display(Name = "PDF")] PDF = 5, [Display(Name = "Video")] Video = 6, [Display(Name = "Evidence")] Evidence = 7, [Display(Name = "None")] None = 8, [Display(Name = "Notes")] NOTES = 9, [Display(Name = "Shared Case")] SharedCase = 10, [Display(Name = "Created Case")] CreatedCase = 11, } public AudItTypes AuditTrailType { get; set; } public int Id { get; set; } [StringLength(30)] public string IPAddressBytes { get; set; } public Guid TennantId { get; set; } public int AuditType { get; set; } public int MISObjectId { get; set; } [Required] public string Action { get; set; } public DateTime CreatedDate { get; set; } [StringLength(30)] public string CreatedBy { get; set; } public bool isActive { get; set; } public bool isDeleted { get; set; } }
@{ ViewData["Title"] = "Index"; } <h1>Index</h1> <table id="audTrailTable"> <thead> <tr> <th>CreatedDate</th> <th>createdby</th> <th>action</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> <td></td> </tr> </tbody> </table> @section scripts { <script> $(document).ready(function () { $("#audTrailTable").DataTable({ "ajax": { url: "/DataTable/GetAuditTrailData/", type: "get", database: "json" }, "columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ], "scrollY": "200px", "scrollCollapse": true, "paging": false, "processing": true, // for show progress bar "filter": true, // this is for disable filter (search box) "orderMulti": false // for disable multiple column at once }) }); </script> }
public class DataTableController : Controller { public IActionResult Index() { return View(); } [HttpGet] public ActionResult<DataTableWrapper<List<MISAuditTrail>>> GetAuditTrailData() { DataTableWrapper<List<MISAuditTrail>> data = new DataTableWrapper<List<MISAuditTrail>>() { data = PopulateTestData() }; return data; } public List<MISAuditTrail> PopulateTestData() { List<MISAuditTrail> list = new List<MISAuditTrail>() { new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, }; return list; } }
In the future, please share code that the community can actually run. Take the time to create test data for us to hep you. Frankly, testing should be a part of your development process.
mgebhard
The error message is telling you that something is wring with the first column. I assume it is the column name.
"columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ],
I built a test based on your code and it functions as expected.
public class DataTableWrapper<T> { public T data { get; set; } } public class MISAuditTrail { public enum AudItTypes { [Display(Name = "Microsoft Word")] Word = 1, [Display(Name = "Microsoft Excel")] Excel = 2, [Display(Name = "Image")] Image = 3, [Display(Name = "Voice Recordings")] Voice = 4, [Display(Name = "PDF")] PDF = 5, [Display(Name = "Video")] Video = 6, [Display(Name = "Evidence")] Evidence = 7, [Display(Name = "None")] None = 8, [Display(Name = "Notes")] NOTES = 9, [Display(Name = "Shared Case")] SharedCase = 10, [Display(Name = "Created Case")] CreatedCase = 11, } public AudItTypes AuditTrailType { get; set; } public int Id { get; set; } [StringLength(30)] public string IPAddressBytes { get; set; } public Guid TennantId { get; set; } public int AuditType { get; set; } public int MISObjectId { get; set; } [Required] public string Action { get; set; } public DateTime CreatedDate { get; set; } [StringLength(30)] public string CreatedBy { get; set; } public bool isActive { get; set; } public bool isDeleted { get; set; } }
@{ ViewData["Title"] = "Index"; } <h1>Index</h1> <table id="audTrailTable"> <thead> <tr> <th>CreatedDate</th> <th>createdby</th> <th>action</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> <td></td> </tr> </tbody> </table> @section scripts { <script> $(document).ready(function () { $("#audTrailTable").DataTable({ "ajax": { url: "/DataTable/GetAuditTrailData/", type: "get", database: "json" }, "columns": [ { "data": "createdDate" }, { "data": "createdBy" }, { "data": "action" } ], "scrollY": "200px", "scrollCollapse": true, "paging": false, "processing": true, // for show progress bar "filter": true, // this is for disable filter (search box) "orderMulti": false // for disable multiple column at once }) }); </script> }
public class DataTableController : Controller { public IActionResult Index() { return View(); } [HttpGet] public ActionResult<DataTableWrapper<List<MISAuditTrail>>> GetAuditTrailData() { DataTableWrapper<List<MISAuditTrail>> data = new DataTableWrapper<List<MISAuditTrail>>() { data = PopulateTestData() }; return data; } public List<MISAuditTrail> PopulateTestData() { List<MISAuditTrail> list = new List<MISAuditTrail>() { new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, new MISAuditTrail() { Action = "Action 1", AuditTrailType = MISAuditTrail.AudItTypes.NOTES, AuditType = 1, CreatedBy = "Foo Bar", CreatedDate = DateTime.Now, Id = 1, IPAddressBytes = "10.10.10.10", isActive = true, isDeleted = false, MISObjectId = 1, TennantId = Guid.NewGuid() }, }; return list; } }
In the future, please share code that the community can actually run. Take the time to create test data for us to hep you. Frankly, testing should be a part of your development process.
Monday, August 3, 2020 6:47 PM -
User475983607 posted
IMHO, you are not using view components correctly. The code you've shared is a JavaScript application that uses JSON and has a bit of data binding. Why are you using a view component?
Monday, August 3, 2020 8:05 PM