I had deletes working in my grid but lost some of the code and have been trying without success the last 2 days to get it to work again.
I have a REST service I call to do the actual delete, it is backed by Java. The relevant part of that code is below, followed by my grid.
I have floundered around changing this and that and never can get it to work. The Java Rest Service detects that I am doing a DELETE but I cannot get the parts. I only really need the ID.
What am I doing wrong?
Java based REST service
private void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Map prmMap = request.getParameterMap();
// String id = prmMap.get("id").toString();
String prmUNID = request.getParameter("id");
Database DB = this.getAppData();
// String t = request.getParameter("unid");
Document tmpDoc = DB.getDocumentByUNID(prmUNID);
if (tmpDoc != null) {
tmpDoc.remove(true);
} else {
}
}
script is below
$( document ).ready( function () {
// Add Document
$('#newDoc').click(function(event){
var url = "xpFormPC.xsp";
window.open(url,"_self");
});
// Setup Rest Service
var loc = ( location.href );
var url = loc.substring( 0, loc.lastIndexOf( "/" ) ) + "/xpRest.xsp/custom/";
var searchInput = XSP.getElementById("#searchInput");
var crudServiceBaseUrl = "xpRest1.xsp",
dataSource = new kendo.data.DataSource({
autoSync : true,
transport : {
read : {
url : url + "get?status=5",
dataType : "json",
type : "GET"
},
t
destroy : {
dataType : "json",
url : "destroy?id="
type : "DELETE"
}
},
parameterMap: function(data, type) {
if (type == "destroy") {
return { models: kendo.stringify(data.models) }
}
},
batch:true,
pageSize : 15,
scrollable : false,
height : 600,
schema : {
model : {
id : "unid",
fields : {
serialNumber : {
type : "string",
editable : false
},
statusDescription : {
type : "string",
editable : false
},
lastActionDate : {
type : "date",
editable : false
},
lastActionUser : {
type : "string",
editable : false
},
lastActionLocation : {
type : "string",
editable : false
},
assetTag : {
type : "string",
editable : false
},
model : {
type : "string",
editable : false
},
unid : {
type : "string",
nullable : false
}
}
}
}
});
// Grid
grid = $("#grid").kendoGrid( {
excel:{
fileName: "PC Inventory All.xlsx",
filterable:true,
allPages:false
},
dataSource : dataSource,
dataBound: onDataBound,
columns : [
//define template column with checkbox and attach click event handler
{width: "30px",
template: "<input type='checkbox' class='checkbox' />" },
{
width : "150px",
field : "serialNumber",
title : "Serial Number",
template : "<a href=xpFormPC.xsp?action=openDocument?&key=#=unid#><h5><b>#=serialNumber#</b></h5></a>"
}, {
width : "200px",
field : "statusDescription",
title : "Status"
}, {
width : "250px",
field : "lastActionDate",
title : "Being Decomissioned Date",
template: "#= (lastActionDate == null) ? ' ' : kendo.toString(kendo.parseDate(lastActionDate, 'yyyy-mm-dd'), 'MM/dd/yyyy') #"
}, {
width : "250px",
field : "lastActionUser",
title : "Being Decomissioned User"
}, {
width : "275px",
field : "lastActionLocation",
title : "Being Decomissioned Location"
}, {
width : "150px",
field : "assetTag",
title : "Asset Tag"
}, {
//width : "150px",
field : "model",
title : "Model"
}, {
hidden: false,
width : "50px",
template : "<button type='button' class='btn btn-danger k-grid-delete'>X</button>"
}
],
editable: "inline",
pageable : {
refresh : true,
pageSizes : true,
buttonCount : 5
},
groupable : true,
reorderable : true,
filterable : true,
selectable : true,
sortable : true,
resizable : true,
columnMenu : true
});
// Search
$( "#searchInput" ).keyup( function () {
var selecteditem = $( "#searchInput" ).val();
var kgrid = $( "#grid" ).data( "kendoGrid" );
selecteditem = selecteditem.toUpperCase();
var selectedArray = selecteditem.split( " " );
if ( selecteditem ) {
var orfilter = {
logic : "or",
filters : []
};
var andfilter = {
logic : "and",
filters : []
};
$.each( selectedArray, function ( i, v ) {
if ( v.trim() == "" ) {
} else {
$.each( selectedArray, function ( i, v1 ) {
if ( v1.trim() == "" ) {
} else {
orfilter.filters.push( {
field : "serialNumber",
operator : "contains",
value : v1
}, {
field : "status",
operator : "contains",
value : v1
}, {
field : "curLocation",
operator : "contains",
value : v1
}, {
field : "model",
operator : "contains",
value : v1
}, {
field : "assetTag",
operator : "contains",
value : v1
} );
andfilter.filters.push( orfilter );
orfilter = {
logic : "or",
filters : []
};
}
} );
}
} );
kgrid.dataSource.filter( andfilter );
} else {
kgrid.dataSource.filter( {} );
}
});
var checkedIds = {};
// On click of the checkbox:
function selectRow() {
var checked = this.checked,
row = $(this).closest("tr"),
grid = $("#grid").data("kendoGrid"),
dataItem = grid.dataItem(row);
checkedIds[dataItem.id] = checked;
if (checked) {
//-select the row
row.addClass("k-state-selected");
} else {
//-remove selection
row.removeClass("k-state-selected");
}
}
//on dataBound event restore previous selected rows:
function onDataBound(e) {
var view = this.dataSource.view();
for(var i = 0; i < view.length;i++){
if(checkedIds[view[i].id]){
this.tbody.find("tr[data-uid='" + view[i].uid + "']")
.addClass("k-state-selected")
.find(".checkbox")
.attr("checked","checked");
}
}}
});