Related
`
class TransactionsGrid {
constructor(productInfoWindowId) {
this._productInfoWindowId = productInfoWindowId;
this._gridTransactionsSelectorId = this._productInfoWindowId + " " + "#gridTransactions";
}
async setGrid(inventoryId, productId) {
this._inventoryId = inventoryId;
this._productId = productId;
let userStore = new UserStore();
$(this._gridTransactionsSelectorId).kendoGrid({
allowCopy: true,
resizable: true,
reorderable: true,
columnMenu: true,
scrollable: true,
selectable: "row",
persistSelection: true,
navigatable: true,
sortable: true,
filterable: {
mode: "menu"
},
pageable: {
pageSizes: [100, 200, 300, "all"],
numeric: false
},
height: window.innerHeight - 200,
columns: [
{
field: "OrderType",
title: userStore.translatedString("frmPurchaseOrder.OrderType"),
width: 120
},
{
field: "DocumentNo",
title: userStore.translatedString("frmCreatePurchaseOrders.DocumentNo"),
width: 130,
},
{
field: "ActorNo",
title: userStore.translatedString("Common.ActorNo"),
width: 120
},
{
field: "Actor",
title: userStore.translatedString("Common.Actor"),
width: 120,
},
{
field: "TransactionDate",
title: userStore.translatedString("uctrlInventoryTrans.TransactionDate"),
width: 125,
attributes: {
style: 'text-align: right;'
},
format: "{0:yyyy-MM-dd}"
},
{
field: "Quantity",
title: userStore.translatedString("Common.Quantity"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
},
{
field: "QtyAfterTransactions",
title: userStore.translatedString("Common.QtyAfterTransactions"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
}
],
dataBound: async function (e) {
var rows = e.sender.content.find('tr');
rows.each(function (index, row) {
var dataItem = e.sender.dataItem(row);
if (dataItem.QtyAfterTransactions < 0) {
$(row).children().addClass('lightRed');
}
});
},
dataSource: {
dataType: "json",
schema: {
model: {
fields: {
InventoryId: { type: "number", editable: false },
ProductID: { type: "number", editable: false },
OrderType: { type: "string", editable: false },
DocumentNo: { type: "number", editable: false },
ActorNo: { type: "number", editable: false },
Actor: { type: "string", editable: false },
TransactionDate: { type: "date", editable: false},
Quantity: { type: "decimal", editable: false },
QtyAfterTransactions: { type: "decimal", editable: false }
}
}
},
batch: false,
transport: {
read: function (options) {
$.ajax({
url: "/ProductRowInfoSite/GetTransactions",
data: {
"inventoryId": inventoryId,
"productId": productId
},
dataType: "json", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
success: function (result) {
// notify the data source that the request succeeded
options.success(result);
misc.SelectFirstRowInGrid(self._gridTransactionsSelectorId);
},
error: function (jqXHR, textStatus, errorThrown) {
displayAjaxError(jqXHR, textStatus, errorThrown);
// notify the data source that the request failed
options.error(jqXHR);
},
type: 'POST'
});
}
},
pageSize: 100
}
});
}
}
` $(this._gridTransactionsSelectorId).kendoGrid({
allowCopy: true,
resizable: true,
reorderable: true,
columnMenu: true,
scrollable: true,
selectable: "row",
persistSelection: true,
navigatable: true,
sortable: true,
filterable: {
mode: "menu"
},
pageable: {
pageSizes: [100, 200, 300, "all"],
numeric: false
},
height: window.innerHeight - 200,
columns: [
{
field: "OrderType",
title: userStore.translatedString("frmPurchaseOrder.OrderType"),
width: 120
},
{
field: "DocumentNo",
title: userStore.translatedString("frmCreatePurchaseOrders.DocumentNo"),
width: 130,
},
{
field: "ActorNo",
title: userStore.translatedString("Common.ActorNo"),
width: 120
},
{
field: "Actor",
title: userStore.translatedString("Common.Actor"),
width: 120,
},
{
field: "TransactionDate",
title: userStore.translatedString("uctrlInventoryTrans.TransactionDate"),
width: 125,
attributes: {
style: 'text-align: right;'
},
format: "{0:yyyy-MM-dd}"
},
{
field: "Quantity",
title: userStore.translatedString("Common.Quantity"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
},
{
field: "QtyAfterTransactions",
title: userStore.translatedString("Common.QtyAfterTransactions"),
width: 120,
attributes: {
style: 'text-align: right;'
},
format: "{0:n2}"
}
],
$(document).ready(function () {
var agenciesData = new kendo.DataToken.DataSource({
type: 'webapi',
transport: {
read: { url: "/api/Agencies/", dataType: "json", data: { activity: getActivity() } },
create: { url: "/api/Agencies", type: "POST", dataType: "json" },
destroy: { url: "/api/Agencies/{0}", type: "DELETE" },
update: { url: "/api/Agencies/{0}", type: "PUT" },
idField: "ID"
},
filter: [{ field: "Activity", operator: "eq", value: getActivity() }],
pageSize: 15,
page: 1,
total: 0,
serverPaging: true,
serverSorting: true,
serverFiltering: true,
schema: {
data: "Data",
total: "Total",
model: {
id: "ID",
fields: {
ID: { editable: false, type: "number" },
AgencyName: { type: "string" },
AgentName: { type: "string" },
Address: { type: "string" },
City: { type: "string" },
Tel1: { type: "string" },
Tel2: { type: "string" },
Pele: { type: "string" },
Activity: { type: "number" },
ToDate: { type: "date" }
}
}
}
});
$("#agenciesGrid").kendoGrid({
dataSource: agenciesData,
toolbar: [{ text: "valid", className: "validAgents" }, { text: "not valid", className: "notValid" }, { text: "all", className: "allAgents" }, { text: "potential", className: "potetial" }],
editable: false,
navigatable: true,
sortable: true,
autoBind: false,
height: 430,
pageable: { refresh: true },
columns: [
{ field: "ID", hidden: true },
{ field: "AgencyName", title: "agency", width: 150, filterable: { cell: { operator: "contains" } } },
{ field: "AgentName", title: "agent", width: 150, filterable: { cell: { operator: "contains" } } },
{ field: "Address", title: "address", width: 200, template: "#= Address + ' ' + City #", filterable: false },
{ field: "Tel1", title: "phones", width: 300, template: "#= Tel1 + ' : ' + Tel2 + ' : ' + Pele #", filterable: false },
{ field: "Activity", title: "active", width: "90px" },
{ field: "ToDate", title: "end Contract", type: "date", width: 90, format: "{0:dd/MM/yyyy}", parseFormats: ["yyyy-MM-ddThh:mm:ss"] }
]
});
$(".validAgents").click(function () { //valid
$("#myActivity").val("1");
$('#agenciesGrid').data().kendoGrid.dataSource.read({ activity: "1" });
});
$(".notValid").click(function () {//notValid
$("#myActivity").val("2");
$('#agenciesGrid').data().kendoGrid.dataSource.read({ activity: "2" });
});
$(".potetial").click(function () {//potetial
$("#myActivity").val("3");
$('#agenciesGrid').data().kendoGrid.dataSource.read({ activity: "3" });
});
});
function getActivity(){
var myActivity = $("#myActivity").val();
return myActivity;
}
When I use kendo grid already filtered by parameter like : $('#someGrid').data().kendoGrid.dataSource.read({ activity: value });
i see the get: https://localhost:44305/api/Agencies/?sort=&page=1&pageSize=15&group=&filter=&activity=1
The grid is filter as expected but, when I want to do paging, sorting, refresh - I get the whole data ignoring the filter that i made.
and I see the get: https://localhost:44305/api/Agencies/?sort=&page=1&pageSize=15&group=&filter=
How can I save my filter state to do paging and sorting on the data came from the server side ?
even when i used differen approach like "scrollable: { virtual: true }" and when i scroll down - every request is without the filtering...
Thanks
Did you try
var agenciesData = new kendo.DataToken.DataSource({
filter : function () {
return object;
}
});
I mean try using filter as a function and you can do your logic inside the function depending on the situation.
I want to add Hierarchy (child) grid on button click event. By default on grid load, there is a child grid. I want it to bind on button click.
var people = new kendo.data.DataSource({
data: {!Output},
batch: true,
schema: {
model: {
fields: {
carId: { type: "string" },
vehicleId: { type: "string", editable:false },
Percentage: { type: "number", editable:false },
Price: { type: "string", editable:false},
CarType: { type: "string", editable:false},
CarSize: { type: "string", editable:false},
CarPerCase: { type: "number", editable:false },
Family: { type: "string", editable:false},
ModelType: { type: "string", editable:false},
EPId: { type: "string" },
Tax: { type: "string" }
}
}
},
pageSize: 20,
sort: { field: "vehicleId", dir: "asc" }
});
var element = $("#grid").kendoGrid({
dataSource: people,
navigatable: true,
pageable: true,
toolbar: [
"save",
"cancel",
{
name: "Add",
text: "Show Car Price",
click: function(e) {
return false;
}
},
{
name: "Delete",
text: "Hide Car Price",
click: function(e) {
return false;
}
}
],
columns:[
{
field: "carId",
title: "Car ID",
width: 150,
hidden:true
},
{
field: "vehicleId",
title: "Vehicle ID",
width: 100
},
{
field: "Percentage",
title: "Percentage",
width: 70
},
{
field: "Price",
title: "Price",
width: 250
},
{
field: "CarType",
title: "Car Type"
},
{
field: "CarSize",
title: "Car Size"
},
{
field: "CarPerCase",
title: "Car Per Case"
},
{
field: "Family",
title: "Family"
},
{
field: "ModelType",
title: "Model Type",
width: 100
},
{
field: "EPId",
title: "EP Id",
hidden: false
},
{
field: "Tax",
title: "Tax",
format: "{0:c}",
width: 100
}
],
editable:true,
groupable: true,
filterable: true,
sortable: true,
reorderable: true,
resizable: true,
columnMenu: true,
pageable: {
refresh: true,
pageSizes: [10, 20, 50],
buttonCount: 5
},
editable: "incell",
detailInit: detailInit
});
// hierarchy grid
function detailInit(e) {
var detailRow = e.detailRow;
codeDetailData = e.data;
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: e.data.ItemPrices.toJSON(),
editable:true,
navigatable: true,
scrollable: false,
sortable: true,
pageable: true,
columns: [
{
field: "Engine",
width: "200px",
editor: serviceItemAutoCompleteEditor
},
{
field: "TN",
title:"TN",
width: "110px"
},
{
field: "TaxApplied",
title:"Tax Applied"
},
{
field: "TaxChange",
title: "Tax Change",
width: "300px"
},
{
field: "StartDate",
title: "Start Date",
format:"{0:dd-MM-yyyy}",
editor: dateTimeEditor
},
{
field: "EndDate",
title: "End Date",
format:"{0:dd-MM-yyyy}",
editor: dateTimeEditor
}
]
});
}
Now the detailInit: detailInit configuration is set on load. I want that load without detailInit (responsible for child grid), and bind this setting on button click. Is it possible?
You will have to add a detail template to tell the grid there is going to be a detailinit grid
var element = $("#grid").kendoGrid({
dataSource: people,
navigatable: true,
toolbar: [
"save",
"cancel", {
name: "Add",
text: "Show Car Price",
click: function (e) {
return false;
}
}, {
name: "Delete",
text: "Hide Car Price",
click: function (e) {
return false;
}
}],
columns: [{
field: "carId",
title: "Car ID",
width: 150,
hidden: true
}, {
field: "vehicleId",
title: "Vehicle ID",
width: 100
}, {
field: "Percentage",
title: "Percentage",
width: 70
}, {
field: "Price",
title: "Price",
width: 100
}, {
field: "CarType",
title: "Car Type"
}, {
field: "CarSize",
title: "Car Size"
}, {
field: "CarPerCase",
title: "Car Per Case"
}, {
field: "Family",
title: "Family"
}, {
field: "ModelType",
title: "Model Type",
width: 100
}, {
field: "EPId",
title: "EP Id",
hidden: false
}, {
field: "Tax",
title: "Tax",
format: "{0:c}",
width: 100
}],
groupable: true,
filterable: true,
sortable: true,
reorderable: true,
resizable: true,
columnMenu: true,
pageable: {
refresh: true,
pageSizes: [10, 20, 50],
buttonCount: 5
},
editable: "incell",
detailTemplate: 'Item Prices: <div class="grid"></div>',
dataBound:function(e){
$(".k-hierarchy-cell").hide();
$(".k-hierarchy-col").hide();
}
});
then bind the detail event to the grid using a click button
$("#testbtn").click(function (e) {
$(".k-hierarchy-cell").show();
$(".k-hierarchy-col").show();
var grid = $("#grid").data("kendoGrid");
grid.unbind("detailInit");
grid.bind("detailInit", grid_detailInit);
grid.refresh();
});
Here is a Jsfiddle Example http://jsfiddle.net/ecotz69h/7/
Im using kendo ui grid and everything is working fine except for update. When i click on the reviewed column the field changes to a check box and i can edit it, and the update gets called but no data is passed in the put request. If i put a breakpoint in the parameter map function the model is null. Javascript code is below:
var selfPayDataSource = new kendo.data.DataSource({
serverFiltering: true, // <-- Do filtering server-side
serverPaging: true, // <-- Do paging server-side
serverSorting: true,
autoSync: true,
pageSize: 100,
batch:false,
//filter: generateDsFilter(),
type: 'odata', // <-- Include OData style params on query string.
sortable: {
mode: "multiple",
allowUnsort: true
},
pageable: {
refresh: true
},
schema: {
data: function (data) {
return data.Items; // <-- The result is just the data, it doesn't need to be unpacked.
},
total: function (data) {
return data["Count"]; // <-- The total items count is the data length.
},
model: {
id: "SelfPayId",
fields: {
resp_ind: { type: "string", editable: false },
cstsv_resolved: { type: "string", editable: false },
cstsv_rep: { type: "string", editable: false },
cstsv_comp_date: { type: "string", editable: false },
region: { type: "string", editable: false },
db: { type: "string", editable: false },
personid: { type: "string", editable: false },
legacyid: { type: "string", editable: false },
account__: { type: "string", editable: false },
deceased: { type: "string", editable: false },
patient_name: { type: "string", editable: false },
account_balance: { type: "number", editable: false },
pat_last_paid_date: { type: "date", editable: false },
pat_last_paid_amt: { type: "number", editable: false },
acct_stat: { type: "string", editable: false },
bill_type: { type: "string", editable: false },
acct_score: { type: "number", editable: false },
tu_status: { type: "string", editable: false },
scoring: { type: "number", editable: false },
coll_ltr: { type: "string", editable: false },
HighestPriPlan: { type: "string", editable: false },
HighestSecPlan: { type: "string", editable: false },
HighestTerPlan: { type: "string", editable: false },
Max_DOS_Aging_Group: { type: "string", editable: false },
Reviewed: { type: "boolean", editable: true },
Collector_Name: { type: "string", editable: false}
}
}
},
transport: {
read: {
url: "/api/SelfPayData/Get", // <-- Get data from here
dataType: "json" // <-- The default was "jsonp"
},
update: {
url: "/api/SelfPayData/PUT",
dataType: "json", // <-- The default was "jsonp"
contentType: "application/json; charset=utf-8",
type: "PUT"
},
parameterMap: function (data, operation) {
if (operation != "read") {
return JSON.stringify(data.models);
} else {
var paramMap = kendo.data.transports.odata.parameterMap(data);
var orderBy = paramMap.$orderby;
if (orderBy == undefined) {
orderBy = "account__";
}else {
orderBy = orderBy + ",account__";
}
paramMap.$orderby = orderBy;
var filter = paramMap.$filter;
if (filter == null || filter == '') {
delete paramMap.$filter;
}
delete paramMap.$format; // <-- remove format parameter.
return paramMap;
}
}
}
});
$(function () {
$("#grid").kendoGrid({
sortable: true,
pageable: true,
scrollable: true,
resizable: true,
editable: true,
navigatable: true,
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
columns: [
{
field: "cstsv_resolved",
title: "Cstsv Resolved",
width: "5em",
filterable: true
},
{
field: "cstsv_rep",
title: "Cstsv Rep",
width: "8em",
filterable: true
},
{
field: "cstsv_comp_date",
title: "Cstsv Comp Date",
width: "6em",
filterable: true
},
{
field: "region",
title: "Region",
width: "5em",
filterable: true
},
{
field: "db",
title: "DB",
width: "4em",
filterable: true
},
{
field: "personid",
title: "Person ID",
width: "6em",
filterable: true
},
{
field: "legacyid",
title: "Legacy ID",
width: "6em",
filterable: true
},
{
field: "account__",
title: "Account #",
width: "6em",
filterable: true
},
{
field: "deceased",
title: "Deceased",
width: "5.2em",
filterable: true
},
{
field: "patient_name",
title: "Patient Name",
width: "6em",
filterable: true
},
{
field: "account_balance",
title: "Account Balance",
width: "5em",
filterable: true,
format: "{0:c2}"
},
{
field: "pat_last_paid_date",
title: "Pat Last Paid Date",
width: "6em",
format: "{0: MM-dd-yyyy}",
filterable: true
},
{
field: "pat_last_paid_amt",
title: "Pat Last Paid Amt",
width: "6em",
filterable: true,
format: "{0:c2}"
},
{
field: "acct_stat",
title: "Acct Stat",
width: "5em",
filterable: true
},
{
field: "bill_type",
title: "Bill Type",
width: "5em",
filterable: true
},
{
field: "acct_score",
title: "Acct Score",
width: "4em",
filterable: true
},
{
field: "tu_status",
title: "TU Status",
width: "6em",
filterable: true
},
{
field: "scoring",
title: "Scoring",
width: "4em",
filterable: true
},
{
field: "coll_ltr",
title: "Coll Ltr",
width: "5em",
filterable: true
},
{
field: "HighestPriPlan",
title: "Pri Plan",
width: "5em",
filterable: true
},
{
field: "HighestSecPlan",
title: "Sec Plan",
width: "5em",
filterable: true
},
{
field: "HighestTerPlan",
title: "Ter Plan",
width: "5em",
filterable: true
},
{
field: "Max_DOS_Aging_Group",
title: "DOS Aging Group",
width: "5em",
filterable: true
},
{
field: "Reviewed",
title: "Reviewed",
width: "10em",
filterable: true
},
{
field: "Collector_Name",
title: "Collector Name",
width: "10em",
filterable: true
}
],
dataSource: selfPayDataSource
});
});
The models field is available only when the batch option is set to true. This doesn't seem to be the case here. The model fields are exposed in the data parameter when batch is set to false.
Refer to the comment inside the AJAX done function below:
$("<div/>").appendTo(e.detailCell).kendoGrid({
reorderable: true,
resizable: true,
dataSource: {
transport: {
read: function()
{
$.ajax({
url: "http://x/y/api/Awards/directors/" + e.data.AwardTitleId,
type: "GET"
}).done(function()
{
//I'm not sure what to do here in order to bind the data returned by the GET to the grid.
});
},
},
schema: {
model: {
id: "namefirstlast",
fields: {
"namefirstlast": { editable: true, type: "string" },
"directorsequence": { editable: true, type: "number", validation: { min: 1 } },
"isonballot": { editable: true, type: "boolean" },
"concatenation": { editable: true, type: "string" },
"MoreNames": { editable: true, type: "number", validation: { min: 0 } },
},
},
}
},
columns: [
{ field: "namefirstlast", title: "Name", editor: namesAutoComplete },
{ field: "directorsequence", title: "Director Sequence", format: "{0:n0}" },
{ field: "isonballot", title: "On ballot?" },
{ field: "concatenation", title: "Concatenation" },
{ field: "MoreNames", title: "More names?", format: "{0:n0}" },
{ command: ["edit"], title: " ", width: 100 }],
sortable: true,
sort: { field: "namefirstlast", dir: "desc" },
editable: "inline",
toolbar: [{ name: "create", text: "Add New Director/Recipient" }]
});
Figured it out:
detailRow.find(".directorsOrRecipients").data("kendoGrid").dataSource.read();
detailRow.find(".directorsOrRecipients").data("kendoGrid").refresh();