Invalid JSON primitive: Date - c#

I keep getting the following error: "Invalid JSON primitive: Date". I am not sure how to correct as I have changes to the front/back-end of the project. Everything seems to be working other than when I de-bug the JavaScript. My front-end code is as follows (I only included some HTML, where a date is used):
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent"
runat="server">
<script>
$("#Grid").kendoGrid({
"dataSource": {
"transport": {
"read": {
"url": "CreateReq.aspx/PopulateMessages",//page then function
contentType: "application/json; charset=utf-8",
type: "GET",
dataType: "json",
"data": {
requestID: document.getElementById("lblRequestID").textContent
}
},
create: {
url: "CreateReq.aspx/CreateMessage",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
"data": {
}
},
"prefix": ""
},
"schema": {
data: function (response) {
return response.d;
},
model: {
fields: {
Date: { type: "date",editable: false, format: "{0: MM/dd/yyyy}", encoded: true, /*defaultValue: Date.now*/ },
Author: { type: "string", editable: true},
Message: { type: "string" },
}
}
},
},
//pageable: true,
height: 225,
toolbar: ["create"],
columns: [
{ field: "Date", title: "Date", width: "75px", /*template: '#= kendo.toString((Date), "MM/dd/yyyy")#'*/ format: "{0: MM/dd/yyyy}", encoded: true},
{ field: "Author", title: "Author", width: "75px" },
{ field: "Message", title: "Message", width: "300px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }],
editable: "inline"
});
});
</script>
<h1 style="text-align: center">Academic Code Request</h1>
<div class="TopPageButtons" style="text-align: center">
<br />
</div>
<div class="TrackingBox">
<div class="TrBoxContent">
<div>
<label><b>ID</b></label><br />
<asp:Label ID="lblRequestID" Text="" runat="server" ClientIDMode="Static"/>
</div>
<div>
<label><b>Form View Date</b></label><br />
<asp:TextBox ID="RequestDate" runat="server" ClientIDMode="Static" style="text-align:center"/>
<script>
document.getElementById("RequestDate").value = new Date().toString();
</script>
</div>

Related

Jquery Data Table - No data available in table

I have developed an application using .net core. One of my requirements is datatables. In my controller I am calling a REST Api service and returning a Json result. The view is pretty straight forward in that of my html table and the AJAX call to the controller for data. Upon execution of the application my datatable shows up with 'No data available in table'
<table id="datatable">
<thead class="thead-light">
<tr role="row">
<th class="table-column-pr-0 sorting_disabled" rowspan="1" colspan="1" aria-label="" style="width: 44px;">
<div class="custom-control custom-checkbox">
<input id="datatableCheckAll" type="checkbox" class="custom-control-input">
<label class="custom-control-label" for="datatableCheckAll"></label>
</div>
</th>
<th class="table-column-pl-0 sorting" tabindex="0" aria-controls="datatable" rowspan="1" colspan="1" style="width: 299px;">UserID</th>
<th class="table-column-pl-0 sorting" tabindex="0" aria-controls="datatable" rowspan="1" colspan="1" style="width: 299px;">UserName</th>
<th class="sorting" tabindex="0" aria-controls="datatable" rowspan="1" colspan="1" style="width: 195px;">DepartmentID</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js">
</script>
<script>
$(function () {
$.ajax({
type: "POST",
url: "/ApplicationUsers/LoadData",
data: '{}',
contentType: "application/json; charset=utf-8",
headers: { 'Access-Control-Allow-Origin': '*' },
dataType: "json",
success: function (response) {
OnSuccess(response);
},
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
// INITIALIZATION OF DATATABLES
// =======================================================
function OnSuccess(response) {
console.log(response);
$.noConflict();
$('#datatable').DataTable(
{
dom: 'Bfrtip',
bLengthChange: true,
lengthMenu: [[5, 10, -1], [5, 10, "All"]],
bFilter: true,
bSort: true,
bPaginate: true,
searching: false,
data: response,
columns: [
{ 'data': 'userID', "defaultContent": "", },
{ 'data': 'userName', "defaultContent": "", },
{ 'data': 'departmentID', "defaultContent": "", }]
});
};
</script>
public class ApplicationUsersController : Controller
{
[HttpGet]
public ActionResult Users()
{
return View();
}
[HttpPost]
public ActionResult LoadData()
{
var data = ClaimsService.GetUsers();
return Json(new { data = data});
}
}
JSON DATA
{"data":{"result":[{"userID":322,"userName":"Ashnee","departmentID":3,"branchID":1,"name":"Ashnee Pillay ","emailAddress":"Ashnee#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":323,"userName":"BalanC","departmentID":15,"branchID":5,"name":"Balan Chetty ","emailAddress":"BalanC#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":328,"userName":"BrettL","departmentID":1,"branchID":1,"name":"Brett Lange ","emailAddress":"BrettL#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":334,"userName":"CoenieB","departmentID":14,"branchID":4,"name":"Coenie De Beer ","emailAddress":"CoenieB#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":337,"userName":"TraceyA","departmentID":61,"branchID":30,"name":"Tracey De Andrade ","emailAddress":"TraceyA#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":350,"userName":"HenryB","departmentID":18,"branchID":8,"name":"Henry Barber ","emailAddress":"HenryB#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":351,"userName":"HowardG","departmentID":6,"branchID":1,"name":"Howard Gains ","emailAddress":"HowardG#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":354,"userName":"IreneK","departmentID":17,"branchID":7,"name":"Irene Koegelenberg ","emailAddress":"IreneK#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":356,"userName":"JayM","departmentID":2,"branchID":1,"name":"Jay Mahillal ","emailAddress":"JayM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":359,"userName":"TheshniR","departmentID":4,"branchID":1,"name":"Theshni Reddy ","emailAddress":"TheshniR#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":363,"userName":"Mariov","departmentID":15,"branchID":5,"name":"Mario Vincent ","emailAddress":"mariov#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":366,"userName":"Rehana","departmentID":3,"branchID":1,"name":"Rehana Adams ","emailAddress":"Rehana#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":368,"userName":"FrancoisC","departmentID":19,"branchID":9,"name":"Francois Cloete ","emailAddress":"FrancoisC#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":369,"userName":"CharneW","departmentID":22,"branchID":10,"name":"Charne Wagner ","emailAddress":"CharneW#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":372,"userName":"Rajeshree","departmentID":3,"branchID":1,"name":"Rajeshree Singh ","emailAddress":"Rajeshree#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":377,"userName":"SamanthaM","departmentID":2,"branchID":1,"name":"Samantha Murugan ","emailAddress":"SamanthaM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":381,"userName":"SueP","departmentID":2,"branchID":1,"name":"Sue Pillay ","emailAddress":"SueP#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":382,"userName":"Sunitha","departmentID":3,"branchID":1,"name":"Sunitha Kandhai ","emailAddress":"Sunitha#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":385,"userName":"TraceyL","departmentID":20,"branchID":12,"name":"Tracey Lambooy ","emailAddress":"TraceyL#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":387,"userName":"Vinola","departmentID":80,"branchID":30,"name":"Vinola Kalideen ","emailAddress":"Vinola#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":397,"userName":"MarioL","departmentID":5,"branchID":1,"name":"Mario Luis","emailAddress":"MarioL#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":403,"userName":"SteveJ","departmentID":9,"branchID":14,"name":"Steve Jarman","emailAddress":"SteveJ#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":404,"userName":"MarkN","departmentID":18,"branchID":1,"name":"Mark Naicker","emailAddress":"MarkN#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":406,"userName":"MosesQ","departmentID":18,"branchID":8,"name":"MosesQwabe","emailAddress":"MosesQ#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":407,"userName":"Evonn","departmentID":3,"branchID":1,"name":"Evonn Naicker","emailAddress":"Evonn#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":417,"userName":"Brandon","departmentID":18,"branchID":8,"name":"Brandon Booysen","emailAddress":"BrandonBO#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":419,"userName":"SifisoD","departmentID":9,"branchID":14,"name":"Sifiso Dlamini","emailAddress":"SifisoD#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":423,"userName":"Jnb.Workshop","departmentID":9,"branchID":14,"name":"Jnb.Workshop","emailAddress":"Jnb.Workshop#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":425,"userName":"PrenishaS","departmentID":15,"branchID":5,"name":"Prenisha Sami","emailAddress":"Prenishas#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":426,"userName":"Pzb.Operations","departmentID":20,"branchID":12,"name":"Gift Kunene","emailAddress":"Pzb.Operations#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":427,"userName":"SalomeM","departmentID":18,"branchID":8,"name":"Salome Mokwele","emailAddress":"SalomeM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":431,"userName":"GeorgeH","departmentID":12,"branchID":3,"name":"George Horn","emailAddress":"GeorgeH#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":434,"userName":"NadineF","departmentID":22,"branchID":10,"name":"Nadine Feldtmann","emailAddress":"NadineF#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":435,"userName":"ThiroshanN","departmentID":2,"branchID":1,"name":"Thiroshan Naicker","emailAddress":"ThiroshanN#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":442,"userName":"GeneN","departmentID":14,"branchID":4,"name":"Gene Naidoo","emailAddress":"GeneN#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":444,"userName":"Jnb.Boardroom","departmentID":1,"branchID":1,"name":"Jnb.Boardroom","emailAddress":"Jnb.Boardroom#Tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":447,"userName":"Mariob","departmentID":65,"branchID":37,"name":"Mario Botha","emailAddress":"Mariob#tritonfleet.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":449,"userName":"KureshaM","departmentID":3,"branchID":1,"name":"Kuresha Moodley","emailAddress":"KureshaM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":453,"userName":"SeanR","departmentID":3,"branchID":1,"name":"Sean Raidoo","emailAddress":"SeanR#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":459,"userName":"SalonaB","departmentID":3,"branchID":1,"name":"Salona Balram","emailAddress":"SalonaB#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":460,"userName":"JohannesS","departmentID":18,"branchID":8,"name":"Johannes Van Staden","emailAddress":"JohannesS#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":463,"userName":"Dannyg","departmentID":15,"branchID":5,"name":"Danny Govender","emailAddress":"dannyg#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":466,"userName":"Shaneilr","departmentID":5,"branchID":1,"name":"Shaneil","emailAddress":"shaneilr#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":468,"userName":"BlessingM","departmentID":19,"branchID":9,"name":"Blessing Mlimi","emailAddress":"BlessingM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":477,"userName":"EnvorS","departmentID":13,"branchID":2,"name":"Envor Swart","emailAddress":" envors#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":481,"userName":"FritzB","departmentID":59,"branchID":25,"name":"Fritz Beudeker","emailAddress":"FritzB#tritonscs.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":483,"userName":"JuanP","departmentID":6,"branchID":1,"name":"Juan Potgieter","emailAddress":"JuanP#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":484,"userName":"NonhlanhlaMn","departmentID":18,"branchID":8,"name":"Nonhlanhla Mnguni ","emailAddress":"NonhlanhlaM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":488,"userName":"WinnieM","departmentID":18,"branchID":8,"name":"Winnie Mbongo","emailAddress":"WinnieM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":492,"userName":"JaendreS","departmentID":16,"branchID":6,"name":"Jaendre Serfontein","emailAddress":"JaendreS#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":497,"userName":"TshepoM","departmentID":18,"branchID":8,"name":"Tshepo Mbele","emailAddress":"TshepoM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":498,"userName":"ItumelengL","departmentID":18,"branchID":8,"name":"Itumeleng Leso","emailAddress":"ItumelengL#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":499,"userName":"Raynoldn","departmentID":18,"branchID":8,"name":"Raynold Ngwane","emailAddress":"Raynoldn#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":504,"userName":"JarredM","departmentID":58,"branchID":24,"name":"Jarred Metzler","emailAddress":"JarredM#tritonscs.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":511,"userName":"MagdaG","departmentID":6,"branchID":1,"name":"Magda Greeff","emailAddress":"MagdaG#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":513,"userName":"WinstonB","departmentID":55,"branchID":28,"name":"Winston Blaine","emailAddress":"WinstonB#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":517,"userName":"ByronV","departmentID":27,"branchID":17,"name":"Byron Vickers ","emailAddress":"ByronV#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":521,"userName":"GertH","departmentID":61,"branchID":48,"name":"Gert Hael ","emailAddress":"GertH#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":523,"userName":"Nomsat","departmentID":88,"branchID":45,"name":"Nomsa Tshabalala","emailAddress":"NomsaT#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":527,"userName":"AndrewJ","departmentID":18,"branchID":8,"name":"Andrew Julius","emailAddress":"AndrewJ#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":528,"userName":"LeeH","departmentID":4,"branchID":1,"name":"Lee Hamberger","emailAddress":"LeeH#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":530,"userName":"KevinS","departmentID":4,"branchID":1,"name":"Kevin Smith","emailAddress":"KevinS#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":532,"userName":"PhumeleleM","departmentID":63,"branchID":33,"name":"Phumelele","emailAddress":"PhumeleleM#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":533,"userName":"GiftK","departmentID":20,"branchID":12,"name":"Gift Kunene","emailAddress":"Giftk#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":534,"userName":"MiguelF","departmentID":55,"branchID":28,"name":"Miguel","emailAddress":"MiguelF#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":535,"userName":"BilkisA","departmentID":2,"branchID":1,"name":"Bilkis Ahmod","emailAddress":"bilkisa#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":539,"userName":"HermanK","departmentID":24,"branchID":15,"name":"Herman Kleynhans","emailAddress":"HermanK#tritonexpress.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":543,"userName":"SomP","departmentID":58,"branchID":24,"name":"Som Pillay","emailAddress":"SomP#tritonscs.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"},{"userID":544,"userName":"AndriesG","departmentID":73,"branchID":42,"name":"Andries Greyling","emailAddress":"AndriesG#tritonscs.co.za","archive_User":"0","managerID":0,"isHeadOffice":0,"statusID":1,"statusDate":"0001-01-01T00:00:00"}],"id":1601,"exception":null,"status":5,"isCanceled":false,"isCompleted":true,"isCompletedSuccessfully":true,"creationOptions":0,"asyncState":null,"isFaulted":false}}
Your JSON data has the following overall structure:
{
"data": {
"result": [
{...},
{...},
{...},
...
{...}
],
"id": 1601,
"exception": null,
...
"isFaulted": false
}
}
The "result": [ ] array is where you see the data needed to populate the table. Each {...} object in that array represents one row of table data.
Therefore you have to point DataTables at that array, so it knows where, inside your JSON, to look for the data it will display. DataTables will automtically handle iteration over each item in that array.
This is why you needed to change this:
data: response,
to this:
data: response.data.result,
in your DataTable definition. Here, response is the name of the variable containing the overall response JSON. And data.result is the specific location inside that JSON where your table data is stored.

How to search grid by textbox ID?

I am Using jqgrid in mvc 4. I want to show grid data only those data which match with OrderNo. Grid is showing but data is not showing. Here is Controller where i am writing my sql search method for filtering data. please suggest me the better way to search data in grid view?
public ActionResult getItemsByOrder(string OrdNo)
{
try
{
List<OrderDtl> itm = db.Fetch<OrderDtl>("select * from OrderDtls where OrderNo=" + OrdNo).ToList();
return Json(itm, JsonRequestBehavior.AllowGet);
}
catch
{
return Json(null, JsonRequestBehavior.AllowGet);
}
}
Here is my script. I think my problem is in url: line or in controller. Please Help me to solve my solution.
</script>
<link rel="stylesheet" type="text/css" href="/scripts/css/ui.jqgrid.css" title="coffee" media="screen" />
<script src="~/Scripts/jqgrid/grid.locale-en.js" type="text/javascript"></script>
<script src="~/Scripts/jqgrid/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="~/Scripts/js/jqModal.js" type="text/javascript"></script>
<script src="~/Scripts/js/jqDnR.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
var ord = $('#OrderNo').val();
jQuery("#list").jqGrid({
url: '/NewOrder/getItemsByOrder/' + ord,
datatype: 'json',
mtype: 'GET',
colNames: ['ItemId', 'ItemName', 'Quantity', 'Rate', 'Amount', 'Action'],
colModel: [
{ name: 'ItemId', index: 'Id', width: 100, align: 'left' },
{ name: 'ItemName', index: 'ItemName', width: 100, align: 'left' },
{ name: 'Quantity', index: 'Quantity', width: 200, align: 'left' },
{ name: 'Rate', index: 'Rate', width: 200, align: 'left' },
{ name: 'Amount', index: 'Amount', width: 200, align: 'left' },
{ name: 'Action', index: 'Action', width: 100, align: 'left' }
],
cellEdit: true,
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'ItemId',
sortorder: "desc",
viewrecords: true,
width: 950,
imgpath: '/scripts/themes/coffee/images',
caption: 'Order Details Grid'
});
});
</script>

Align Grid JQuery

I need an help to align this table. I don't know work with design. How I can align and adapt size to each column, and the table in full size in my window?
I want all auto align. Width and Height (Full size).
My code:
$(document).ready(function () {
source =
{
datatype: "xml",
datafields: [
{ name: 'User', type: 'string' },
{ name: 'AccessGroup', type: 'string' },
{ name: 'FolderAccess', type: 'string' },
{ name: 'RequestDate', type: 'Date' },
{ name: 'SituationDesc', type: 'string' },
{ name: 'Approver', type: 'string' },
{ name: 'ApprovalDate', type: 'Date' },
{ name: 'BusinessJustification', type: 'string' },
{ name: 'AllBusinessJustification', type: 'string' },
{ name: 'UserRequestor', type: 'string' }
],
async: false,
record: 'Table',
url: 'Tickets.aspx/GetTickets',
};
var dataAdapter = new $.jqx.dataAdapter(source, {
contentType: 'application/json; charset=utf-8'}
);
$("#jqxgrid").jqxGrid(
{
width: 3000,
source: dataAdapter,
theme: 'classic',
autoheight: true,
columns: [
{ text: 'User', datafield: 'User', widht: 'auto' },
{ text: 'Access Group', datafield: 'AccessGroup', widht: 'auto' },
{ text: 'Folder Access', datafield: 'FolderAccess', widht: 'auto' },
{ text: 'Request Date', datafield: 'RequestDate', widht: 'auto' },
{ text: 'Situation', datafield: 'SituationDesc', widht: 'auto' },
{ text: 'Approver', datafield: 'Approver', widht: 'auto' },
{ text: 'Approval Date', datafield: 'ApprovalDate', widht: 'auto' },
{ text: 'Business Justification', datafield: 'BusinessJustification', widht: 'auto' },
{ text: 'All Business Justifications', datafield: 'AllBusinessJustification', widht: 'auto' },
{ text: 'User Requestor', datafield: 'UserRequestor', widht: 'auto' },
]
});
});
<body>
<form id="form1" runat="server">
<div>
<div align="center" style="width: 100%; height: 100%;">
<img src="image/NdriveBanner.png" align="center" />
</div>
<br />
<br />
<div id="jqxgrid">
</div>
<br />
<br />
<div align="center" style="width: 100%; height: 100%;">
<asp:HyperLink ID="HyperLink2" runat="server" ImageUrl="~/image/home_back_48.png"
NavigateUrl="~/home.aspx">homepage</asp:HyperLink>
</div>
</div>
</form>
Here's a sample code which shows how to set the Grid's size in percentages so it will be auto-resized.
<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>In this sample, the Grid's size is set in percentages. When you resize the browser's window, the Grid's Width and Height will be automatically adjusted. The "width" and "height" properties of jqxGrid in this sample are set to "50%"</title>
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="../../scripts/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcalendar.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdatetimeinput.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
<script type="text/javascript" src="../../jqwidgets/globalization/globalize.js"></script>
<script type="text/javascript" src="../../scripts/gettheme.js"></script>
<script type="text/javascript" src="generatedata.js"></script>
<style>
body, html {
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
var theme = getDemoTheme();
var data = generatedata(500);
var source =
{
localdata: data,
datafields:
[
{ name: 'name', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'available', type: 'bool' },
{ name: 'date', type: 'date'},
{ name: 'quantity', type: 'number' }
],
datatype: "array"
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid(
{
width: '50%',
height: '50%',
source: dataAdapter,
showfilterrow: true,
filterable: true,
theme: theme,
selectionmode: 'multiplecellsextended',
columns: [
{ text: 'Name', columntype: 'textbox', datafield: 'name', width: '20%' },
{
text: 'Product', datafield: 'productname', width: '35%'
},
{ text: 'Ship Date', datafield: 'date', filtertype: 'date', width: '30%', cellsalign: 'right', cellsformat: 'd' },
{ text: 'Qty.', datafield: 'quantity', width: '15%', cellsalign: 'right' }
]
});
});
</script>
</head>
<body class='default'>
<div id="jqxgrid">
</div>
</body>
</html>
jqgrid is providing the align property to each columns, to align header you need to change in the jqgrid css to the respective call for the headers.
for the align in columns you can add like this
$("#jqxgrid").jqxGrid(
{
width: 3000,
source: dataAdapter,
theme: 'classic',
autoheight: true,
columns: [
{ text: 'User', datafield: 'User', widht: 'auto',align="center" },
{ text: 'Access Group', datafield: 'AccessGroup', widht: 'auto',align="center" },
{ text: 'Folder Access', datafield: 'FolderAccess', widht: 'auto',align="center" },
{ text: 'Request Date', datafield: 'RequestDate', widht: 'auto',align="center" },
{ text: 'Situation', datafield: 'SituationDesc', widht: 'auto',align="center" },
{ text: 'Approver', datafield: 'Approver', widht: 'auto' ,align="center"},
{ text: 'Approval Date', datafield: 'ApprovalDate', widht: 'auto',align="center" },
{ text: 'Business Justification', datafield: 'BusinessJustification', widht: 'auto',align="center" },
{ text: 'All Business Justifications', datafield: 'AllBusinessJustification', widht: 'auto',align="center" },
{ text: 'User Requestor', datafield: 'UserRequestor', widht: 'auto' ,align="center"},
]
});

Dialog reloading Partial - JQuery doesn't work (MVC 3)

When I open dialog all things work correct but when I close dialog and I try open this again I have got problem with JQuery (animation, hide etc.) Probably Partial View all the time is working and when dialog is showed again it doesn't mean Partial View is also new. How to fix it?
This doesn't work
<script type="text/javascript">
$('#bladReje').hide();
$('#bladRejeText').hide();
$('#poprawnieReje').hide();
$('#poprawnieRejeText').hide();
</script>
Partial
data.View
AJAX
$.ajax({
url: '#Url.Action("Reje", "Log")',
dataType: "json",
type: "POST",
async: false,
error: function () {
},
success: function (data) {
if (data.Success) {
var el1 = $('<div><strong style="color: black">' + data.View + '</strong></div>');
$(el1).dialog(
{
modal: true,
title: '<div></div>',
minWidth: 340,
minHeight: 300,
buttons: {
'close': function () {
$(this).dialog("destroy");
}
}
});
}
}
});
});
This is example of my Partial View
<div id="bladReje" style="padding: 0px; width: 100%; margin: 0 auto; padding: 0 auto; text-align: left;
font-family: arial; visibility:hidden;">
<div id="bladRejeText" style="font-size: 16px; visibility:hidden;">
</div>
</div>
#Html.TextBoxFor(m => m.Example, new { style = "width:220px" })
<input type="button" class="button" value="Zapisz" onclick="SaveRejestracja();" style="float: right; margin-right: 30px;"/>
<script type="text/javascript">
$('#bladReje').hide();
$('#bladRejeText').hide();
</script>
<script type="text/javascript">
function SaveRejestracja() {
var Example = $('#Example').val();
$.ajax({
url: '#Url.Action("Example", "ControllerExample")',
dataType: "json",
data: {
Nick: Example
},
type: "POST",
traditional: true,
async: false,
error: function () {
},
success: function (data) {
if (data.Success) {
$('#bladReje').hide();
$('#bladReje').css({ visibility: "hidden" });
$('#bladRejeText').hide();
$('#bladRejeText').css({ visibility: "hidden" });
}
if (!data.Success) {
$('#bladReje').hide();
$('#bladReje').css({ visibility: "visible" });
$('#bladRejeText').hide();
$('#bladRejeText').css({ visibility: "visible" });
}
}
});
}
</script>
This work only first time
<script type="text/javascript">
$('#bladReje').hide();
$('#bladRejeText').hide();
</script>

On select Row doesn't activate event in jqgrid

I have a jqGrid on which clicking of a row should render a partial view below the jqGrid, but it doesn't happen. I am doing something as shown below:
<script type="text/javascript" src="#Url.Content("~/Scripts/jquery.jqGrid.min.js")"></script>
<script type="text/javascript" src="#Url.Content("~/Scripts/jquery.cookie.js")"></script>
<script type="text/javascript" src="#Url.Content("~/Scripts/json2.js")"></script>
<script type="text/javascript" src="#Url.Content("~/Scripts/CookieManagement.js")"></script>
<script type="text/javascript" src="#Url.Content("~/Scripts/jQGridState.js")"></script>
<link href="#Url.Content("~/Content/jquery.jqGrid/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$('#Listing').jqGrid({
url: '#Url.Action("Grid", "Name")',
datatype: "json",
edit: false,
add: false,
del: false,
height: 330,
mtype: 'GET',
colNames: ['ID','Name'],
jsonReader: {
root: "Clients",
page: "CurrentPage",
total: "TotalPages",
records: "TotalRecords",
repeatitems: false,
cell: "",
id: "0"
},
colModel: [
{ name: 'Id', index: 'Id', width: 65, align: 'center', sorttype: "int" },
{ name: '#NameMap.STATUS_COLUMN', index: '#NameMap.STATUS_COLUMN', width: 140, align: 'left', sortable: true }],
pager: '#pager',
rowNum: 10,
rowList: [10, 15, 20],
sortname: 'Id',
sortorder: 'asc',
viewrecords: true,
gridview: true,
onSelectRow: function (id) {
$.ajax({
url: '#Url.Action("Details","Name")',
data: { 'Id': id },
success: function (detailsHtml) {
$('#NameDetails').html(detailsHtml);
},
dataType: 'html'
});
},
loadComplete: function () {
$('#NameDetails').html("");
}
});
});
});
</script>
Here Details and Grid are the controller action in the Name Controller. Details which is hooked up to onSelectRow returns a View and $('#NameDetails') is the id of the last div in this page.
My problem is that I am not able to see the details view appearing even though the values inside it are properly getting populated, is there something wrong in my OnSelectRow or do i need to include any other javascript file??
Well that was foolish, but actually I did a spelling mistake in an id called "NameDetails" as "NameDetalis" and that was the reason that my view was not getting rendered.

Categories