Archive for November 2015
MVC with Ajax and InitJQGrid
Save Functions( Ajax)
function SaveEventDetails() {var startDate = $("#txt-event-start-date").val();
var startTime = $("#txt-event-start-time").val();
var endDate = $("#txt-event-end-date").val();
var endTime = $("#txt-event-end-time").val();
//alert(startDate); alert(startTime); alert(endDate); alert(endTime);
if ($("#txt-event-title").val() != "") {
var title = $("#txt-event-title").val();
var description = $("#txt-event-description").val();
var startTime = startDate + " " + startTime;
var endTime = endDate + " " + endTime;
var location = $("#txt-event-location").val();
//var event_ = {
// EventTitle: title, Description: description, StartDateTime: '', EndDateTime: '', Location: location
//};
var event_ = {};
event_["EventTitle"] = title;
event_["Description"] = description;
event_["StartDateTime"] = startTime;
event_["EndDateTime"] = endTime;
event_["Location"] = location;
$.ajax({
type: "POST", // Type
data: JSON.stringify({ 'event_': event_, 'arrTickets': arrTickets }),
dataType: 'json',
url: "Event/AddEvent",
async: false,
contentType: "application/json",
success: function (msg) {
$("#txt-event-title").val() = "";
$("#txt-event-description").val() = "";
$("#txt-event-location").val() = "";
LoadEventsToGrid();
}
});
}
else {
$("#spn-title-error").html('Enter the Title');
$("#spn-title-error").parent().removeClass("form-group has-success");
$("#spn-title-error").parent().addClass("form-group has-error");
}
//bootbox.dialog({
// message: "Invoice saved successfully",
// title: "SM Information",
// buttons: {
// danger: {
// label: "OK",
// className: "btn-success",
// callback: function () {
// }
// }
// }
//});
//$("#txt-event-title").val() = "aa";
//$("#txt-event-description").val() = "aa";
//$("#txt-event-location").val() = "";
//$("#spn-save-msg").html('Event Saved Successfully !');
//$("#spn-save-msg").parent().addClass("form-group has-success");
//$("#spn-save-msg").parent().removeClass("form-group has-error");
//alert("Success !");
}
----------------------------------------------------------------------------------
JQGrid Initializer
function InitializeGrid (){
$("#tbl-evnts").jqGrid({
datatype: "json",
colNames: ["Event ID", "Event Title", "Description", "StartDateTime", "EndDateTime","Location"],
colModel: [
{ name: "EventID", index: "EventID", hidden: true },
{ name: "EventTitle", index: "EventTitle" },
{ name: "Description", index: "Description" },
{ name: 'StartDateTime', index: 'StartDateTime', editable: false, formatter: 'datetime'},
{ name: 'EndDateTime', index: 'EndDateTime', editable: false },
{ name: 'Location', index: 'Location', editable: false }
],
rowNum: 25,
rowList: [5, 10, 20],
viewrecords: true,
sortorder: "asc",
autowidth: true,
height: "100%",
width: "100%",
hiddengrid: false,
//cellEdit: true,
cellsubmit: 'clientArray',
// multiselect: true,
// shrinkToFit: false,
caption: "Event Details",
onSelectRow: function (rowid, status) {
}
//
});
LoadEventsToGrid();
}
function LoadEventsToGrid() {
var grid = $("#tbl-evnts");
grid.clearGridData();
// var dataObject = JSON.stringify({ 'location_id': location_id });
$.ajax({
// data: dataObject,
url: 'Event/ViewEvents',
type: 'post',
contentType: 'application/json',
success: function (inputParam) {
// $("#student-grid-array").removeAll();
for (var i = 0; i < inputParam.length; i++) {
grid.addRowData(i, inputParam[i]);
}
}
});
}
---------------------------------------
function DeleteFormatter(cellvalue, options, rowObject) {
//alert(cellvalue);
DeleteTicket = function (id)
{
//alert(id);
arrTickets.splice(0,1);
AddTicketsToGrid();
}
// var img = '
';var img = '
';//alert(rowObject['ID']);
return img;
}