1
Help for ParamQuery Grid (free version) / Re: How can I display an error message when JSON call fails?
« on: February 09, 2016, 07:35:04 pm »
Thanks for the help
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
var dataModel =
{
location: "remote",
dataType: "json",
method: "POST",
contentType: "application/json; charset=UTF-8",
url: '@Url.RouteUrl("GetChangeOrders")',
getData: function (dataJson)
{
return { data: dataJson };
}
};
var obj =
{
collapsible: false,
colModel: colModel,
dataModel: dataModel,
editable: false,
filterModel: { on: true, mode: "AND", header: true },
flexHeight: true,
numberCell: { show: false },
roundCorners: true,
scrollModel: [lastColumn = "None"],
sortDir: ["up"],
sortIndx: ["ID"],
sorting: "local",
stripeRows: true,
title: "IT Change Orders",
width: $(window).width() - 10,
wrap: false
};
var ChangeTypes = [],
Priorities = [],
ImpactTypes = [],
Users = [];
@foreach (var Type in Model.ChangeTypes)
{
@:ChangeTypes.push("@Type");
}
@foreach (var Type in Model.ImpactTypes)
{
@:ImpactTypes.push("@Type");
}
@foreach (var Priority in Model.Priorities)
{
@:Priorities.push("@Priority");
}
@foreach (var User in Model.Users)
{
@:Users.push("@User");
}
var colModel = [
{ title: "Project ID", dataType: "integer", dataIndx: "ID", hidden: true },
{ title: "Project Name", dataType: "string", dataIndx: "Name", resizable: true, width: 250, halign: "center", filter: { type: 'textbox', condition: 'contain', listeners: ['keyup'] }},
{ title: "Notes", dataType: "string", resizable: false, width: 75, halign: "center" },
{ title: "Change Type", dataType: "string", dataIndx: "Type", resizable: true, width: 169, halign: "center", filter: { type: 'select', options: [ChangeTypes], condition: 'equal', value: 'IN', prepend: { '': '--Select Type--' }, listeners: ['change']}},
{ title: "Priority", dataType: "string", dataIndx: "Priority", resizable: true, width: 55, halign: "center" },
{ title: "Impact", dataType: "string", dataIndx: "Impact", resizable: true, width: 55, halign: "center" },
{ title: "Assigned To", dataType: "string", dataIndx: "AssignedTo", resizable: true, width: 150, halign: "center" },
{ title: "Estimated Start Date", dataType: "date", dataIndx: "EstimatedStartDate", resizable: true, width: 145, halign: "center" },
{ title: "Estimated Completion Date", dataType: "date", dataIndx: "EstimatedEndDate", resizable: true, width: 165, halign: "center" },
{ title: "Date Actually Started", dateType: "date", dataIndx: "DateStarted", resizable: true, width: 145, halign: "center" },
{ title: "Date Actually Compleated", dataType: "date", dataIndx: "DateCompleated", resizable: true, width: 165, halign: "center" },
{ title: "Reason For Change", dataType: "string", dataIndx: "Reason", resizable: true, halign: "center", width: 283, filter: { type: 'textbox', condition: 'contain', listeners: ['keyup'] }},
{ title: "Approval Status", dataType: "string", dataIndx: "ApprovalStatus", resizable: true, width: 105, halign: "center" },
{ title: "Approved By", dataType: "string", dataIndx: "ApprovedBy", resizable: true, width: 135, halign: "center" }
];
$(window).resize(function (evt)
{
var GridWidth = $Grid(window).width() - 10;
var ColumnModel = $Grid.pqGrid("option", "colModel");
//colModel[11].Width = GridWidth - 1459;
colModel[11].Width = 200;
$Grid.pqGrid("option", { width: GridWidth });
$Grid.pqGrid("option", "colModel", ColumnModel);
});
var colModel = [
{ title: "Project ID", dataType: "integer", dataIndx: "ID", hidden: true },
{ title: "Project Name", dataType: "string", dataIndx: "Name", resizable: true, width: 200, halign: "center" },
{ title: "Notes", dataType: "string", resizable: false, width: 75, halign: "center" },
{ title: "Change Type", dataType: "string", dataIndx: "Type", resizable: true, width: 169, halign: "center" },
{ title: "Priority", dataType: "string", dataIndx: "Priority", resizable: true, width: 55, halign: "center" },
{ title: "Impact", dataType: "string", dataIndx: "Impact", resizable: true, width: 55, halign: "center" },
{ title: "Assigned To", dataType: "string", dataIndx: "AssignedTo", resizable: true, width: 150, halign: "center" },
{ title: "Estimated Start Date", dataType: "date", dataIndx: "EstimatedStartDate", resizable: true, width: 150, halign: "center" },
{ title: "Estimated Completion Date", dataType: "date", dataIndx: "EstimatedEndDate", resizable: true, width: 175, halign: "center" },
{ title: "Date Actually Started", dateType: "date", dataIndx: "DateStarted", resizable: true, width: 150, halign: "center" },
{ title: "Date Actually Compleated", dataType: "date", dataIndx: "DateCompleated", resizable: true, width: 175, halign: "center" },
{ title: "Reason For Change", dataType: "string", dataIndx: "Reason", resizable: true, halign: "center" },
{ title: "Approval Status", dataType: "string", dataIndx: "ApprovalStatus", resizable: true, width: 105, halign: "center" },
{ title: "Approved By", dataType: "string", dataIndx: "ApprovedBy", resizable: true, width: 150, halign: "center" }
];
obj.colModel[9].render = function (ui)
{
var cellData = new Date(ui.cellData);
return $.datetimepicker({ dateFormat: "yy-mm-dd", timeFormat: "hh:mm:ss" }, cellData);
}
<script>
$(function ()
{
var colModel = [
{ title: "Project ID", dataType: "integer", dataIndx: "ID", hidden: true },
{ title: "Project Name", dataType: "string", dataIndx: "Name", resizable: true, width: 200 },
{ title: "Notes", dataType: "string", resizable: false, width: 75 },
{ title: "Change Type", dataType: "string", dataIndx: "Type", resizable: true, width: 175 },
{ title: "Priority", dataType: "string", dataIndx: "Priority", resizable: true, width: 75 },
{ title: "Impact", dataType: "string", dataIndx: "Impact", resizable: true, width: 75 },
{ title: "Assigned To", dataType: "string", dataIndx: "Impact", resizable: true, width: 100 },
{ title: "Approval Status", dataType: "string", dataIndx: "ApprovalStatus", resizable: true, width: 100 },
{ title: "Approved By", dataType: "string", dataIndx: "ApprovedBy", resizable: true, width: 150 },
{ title: "Estimated Start Date", dataType: "date", dataIndx: "EstimatedStartDate", resizable: true, width: 150 },
{ title: "Estimated Completion Date", dataType: "date", dataIndx: "EstimatedEndDate", resizable: true, width: 150 },
{ title: "Date Actually Started", dateType: "date", dataIndx: "DateStarted", resizable: true, width: 150 },
{ title: "Date Actually Compleated", dataType: "date", dataIndx: "DateCompleated", resizable: true, width: 150 },
{ title: "Reason For Change", dataType: "string", dataIndx: "Reason", resizable: true }
];
var dataModel =
{
location: "remote",
dataType: "json",
method: "POST",
contentType: "application/json; charset=UTF-8",
url: '@Url.RouteUrl("GetChangeOrders")',
getData: function (dataJson)
{
return { data: dataJson };
}
};
var obj =
{
collapsible: false,
colModel: colModel,
dataModel: dataModel,
editable: false,
flexHeight: true,
numberCell: { show: false },
roundCorners: true,
sortDir: ["up"],
sortIndx: ["ID"],
sorting: "local",
stripeRows: true,
title: "IT Change Orders",
width: $(window).width() - 10,
wrap: false
};
obj.colModel[2].render = function (ui)
{
var rowData = ui.rowData,
dataIndx = ui.dataIndx;
return '<a href="' + '@Url.RouteUrl("ChangeOrderNotes", new { ChangeOrderID = -1 })'.replace("-1", rowData[0]) + '"> Test</a>';
};
var $Grid = $("#Grid").pqGrid(obj);
$(window).resize(function (evt)
{
$Grid.pqGrid("option", { width: $(window).width() - 10 });
});
});
</script>
<script>
$(function ()
{
var colModel = [
{ title: "ID", width: 100, dataType: "integer", dataIndx: "ID" },
{ title: "Name", width: 500, dataType: "string", dataIndx: "Name" }
];
var dataModel =
{
location: "remote",
dataType: "json",
method: "POST",
contentType: "application/json; charset=UTF-8",
url: '@Url.RouteUrl("GetChangeOrders")',
getData: function (dataJson)
{
var data = dataJson.data;
return { data: data };
}
};
var obj =
{
title: "Test",
dataModel: dataModel,
colModel: colModel,
};
$("#Grid").pqGrid(obj);
});
</script>
[Route("GetChangeOrders", Name = "GetChangeOrders")]
public JsonResult ChangeOrders()
{
var ChangeOrdersList = _DbContext.ChangeOrders.Select(co => new { ID = co.ID, Name = co.Name }).ToList();
return Json(ChangeOrdersList);
}