Hi ,
I am working on a some prototypes for my workplace and I am looking for guidance on the best approach. I am relatively new to Kendo and have recently switched from the mvc helpers to Jquery + javascript. I am trying to do the following. My sample code is below.
1. I would like to dynamically generate the cols on the UI using the remote result set. So the result set may contain 25 cols but I only want to paint 5 of them
2. I would like to implement this in reasonably straight forward manner. I was hoping that I could use the datasource fetch but now am no so sure.
3. I would remove the columnheader menu and install my own drop down in the grid toolbar which I would then use to toggle the grid columns on and off. I could then control what columns this would be performed for. I have to do this as there is a restriction on using child grids and frozen cols
The issue that I am encountering is the grid is rendered before I have chance to modify what gets renedered and how. I have seen suggestions that one should destroy the grid prior to rebuilding it. So can you
A.) Indicate if I should create fetch request outside a datasource and use my custom ajax call or should I rebuild the datasource each request
B.) Destroy the grid at each request
B.) Do you have any examples in js where this is done. I have search the web and founds bits and pieces.
Thanks
Ciaran
<div id="container">
<div id="grid"></div>
</div>
<script type="text/javascript">
var baseurl ="http://localhost:5000/api/"
var currentModel;
var requiredColumns=["Id", "CoreId"]
var showOnlyTheseColumns =["Id", "CoreId", "projectName" ]
var DEFAULT_PAGE_SIZE = 15;
var isDateField =[];
var currentColumns =[];
var currentFilters = [];
currentFilters.push({field: 'Id',operator: 'contains',value: '22' });
$(function(){
var grid = $("#grid").kendoGrid({
dataBound: function(e) {
var grid = this;
console.debug('Its too late here its already bound..');
},
dataBinding: function(e){
let grid = this;
grid.columns() =[];
console.debug('databinding called');
},
autoBind: true, //!!! PRETTY SURE THIS SHOULD BE SET TO FALSE. Is this correct? !!!
height: 400,
toolbar: kendo.template($("#toolbarTemplate").html()),
columns:currentColumns,
pageable: {
buttonCount: 6,
refresh: true,
pageSizes: [20, 50, 100, 200],
messages: {
display: "Showing {0}-{1} from {2} " ,
empty: "No records to display",
itemsPerPage: " per page",
}
},
sortable: true,
filterable: true,
scrollable: true,
reorderable: true,
resizable: true,
editable: true,
dataSource: {
serverPaging: true,
serverFiltering: true,
serverSorting: true,
pageSize: DEFAULT_PAGE_SIZE,
sort: {
field: "J.CoreId",
dir: "desc"
},
schema: {
data: "data",
total: "total",
model: currentModel
},
batch: false,
transport: {
create: {
url: baseurl +"Job",
contentType: "application/json",
type: "POST"
},
read: {
url: baseurl +"Job",
contentType: "jsonp",
complete: function (qXHR, textStatus) {
console.log(textStatus, "update");
//Build the model from the source data
currentModel = generateModel(qXHR.responseJSON.data);
//create the columns from the source data
currentColumns =generateColumns(qXHR.responseJSON.data);
console.log('ITS TOO LATE THE GRID IS ALREAYD BOUND ')
$('#grid').data('kendoGrid').refresh();
}
},
update: {
url: baseurl +"Job",
contentType: "application/json",
type: "PUT"
},
destroy: {
url: baseurl +"Job",
contentType: "application/json",
type: "DELETE"
},
parameterMap: function (data, operation) {
currentColumns =[];
return JSON.stringify(data);
}
}
}
});
});
</script>
<script type="text/javascript">
// https://docs.telerik.com/kendo-ui/knowledge-base/create-with-dynamic-columns-and-data-types
function generateColumns(gridData){
for (var property in gridData[0]) {
if (showOnlyTheseColumns.indexOf(property) > -1){
currentColumns.push({field: property,width: "100px", format: (isDateField[name] ? "{0:D}" : "")});
}
}
return currentColumns;
}
Is it possible to just include the kendo.maskedtextbox.min.js in my page? instead of the 3MB kendo.all.min.js file?
What are all the includes needed for maskedtextbox and validation?
Thanks!
Hi, dev teams!
I have two odata source with data like:
ds1 = [id, title] - unique entities here
ds2 = [id,year,value] - multiples entities
I need *title*(ds1) for axeY and *year*(ds2),*value*(ds2) for axeX
So, how i can match this data to one chart by *id*?
Hi,
We are trying to implement Bar/Line charts for our project. We have a specification to remove all extra margins/paddings between titles, labels and plotArea. So far, we could manage to remove for labels and titles but the plotArea still has margins/paddings.
var options = { valueAxis: { background: "red", title: { text: _getSeriesName(), font: chartFont, margin: 0, padding: 0, visible: IsTitlesVisible, background: "blue" }, labels: { font: chartFont, margin: 0, padding: 0, background: "green" }, line: { visible: false } }, series: _getSeries(), categoryAxis: { background: "red", title: { text: _getCategoriesName(), font: chartFont, margin: 0, padding: 0, visible: IsTitlesVisible, background: "blue }, labels: { font: chartFont, margin: 0, padding: 0, background: "green" }, categories: _getCategories(), line: { visible: false } }, plotArea: { margin: 0, padding: 0, background: "orange" }};Please also see the attached file to visualization.
Thanks

Hi team,
About the editor's image browser upload service with imageBrowser.transport.uploadUrl : is there a possibility to set the saveField like it's possible with the upload widget ? Seems the default name is "file" !
Content-Disposition: form-data; name="file"; filename="xxx.jpg"
Content-Type: image/jpeg
Best regards,
Laurent.

I have a grid with a Popup upon edit, but I only want to show 1 or 2 fields in the popup not all of the fields from the selected row, is that possible?
Thanks!
I have a kendoListBox with 12,000 items. This is connected with another kendoListBox and has draggable enabled. Each listbox item has a template applied. The listbox is inside of a modal. When I click a button to open the modal there is a 3 second delay for the modal to open. Then when I try to drag an item or click the arrow buttons to move the item to the opposite list there is another 3 second delay before anything happens. The issue occurred when I changed from a list with only a couple hundred items to this large list. I had this problem with some dropdown boxes and fixed those with virtualization but virtualization does not appear to be available or work here. How do I increase performance so that these components are usable?
<div id="baseModal"> <div class="modal-content"> <div class="modal-header"> <div id="baseModalTitle" class="modal-title">My Modal</div> </div> <div class="modal-body"> <div id="exceptions" class="kendo-dnd-component"> <div class="dnd-list-boxes"> <div class="available-options-container"> <label for="availableItems">Applies To</label> <span class="k-list-filter"> <input id="availableItemsSearchBox" class="k-textbox"><span class="k-icon k-i-zoom"></span> </span> <select id="availableItems" class="browser-default"></select> </div> <div class="selected-options-container"> <label for="selectedItems">Excludes</label> <span class="k-list-filter"> <input id="selectedItemsSearchBox" class="k-textbox"><span class="k-icon k-i-zoom"></span> </span> <select id="selectedItems" class="browser-default"></select> </div> </div> </div> </div> </div> <div class="modal-footer"> <div class="right-align"> <button type="button" class="modal-close waves-effect btn-flat">Cancel</button> <button type="button" class="btn waves-effect ">Accept</button> </div> </div></div><script>function createItemsDragLists() { // List Boxes $("#availableItemsSearchBox").on("input", function (e) { var listBox = $("#availableItems").getKendoListBox(); var sarchString = $(this).val(); listBox.dataSource.filter({ logic: "or", filters: [ { field: "itemID", operator: "contains", value: sarchString }, { field: "itemName", operator: "contains", value: sarchString } ] }); }); $("#selectedItemsSearchBox").on("input", function (e) { var listBox = $("#selectedItems").getKendoListBox(); var sarchString = $(this).val(); listBox.dataSource.filter({ logic: "or", filters: [ { field: "itemID", operator: "contains", value: sarchString }, { field: "itemName", operator: "contains", value: sarchString } ] }); }); $("#availableItems").kendoListBox({ connectWith: "selectedItems", draggable: true, autoScroll: true, dropSources: ["selectedItems"], toolbar: { position: "right", tools: ["transferTo", "transferFrom", "transferAllTo", "transferAllFrom"] }, selectable: "multiple", dataSource: items, template: "<span class='listItemID'>#: data.itemID #</span><span class='listItemName'>#: data.itemName#</span>", valueTemplate: "#: itemName #", dataTextField: "itemName", dataValueField: "itemID" }); $("#selectedItems").kendoListBox({ connectWith: "availableItems", draggable: { placeholder: function (element) { return element.clone().css({ "opacity": 0.3, "border": "1px dashed #000000" }); } }, dropSources: ["availableItems"], selectable: "multiple", template: "<span class='listItemID'>#: data.itemID #</span><span class='listItemName'>#: data.itemName#</span>", valueTemplate: "#: itemName #", dataTextField: "itemName", dataValueField: "itemID" });}</script>
I have a grid that shows data from an uploaded file, the user can delete rows that do now want to upload to the database. If I allow this, then the save/create pass an empty datasource object to my create method in the controller. Is it possible to allow for row deletion and pass the remaining data to my controller so they can all be inserted into the table?
Hello.
I'm having a problem implementing the following scenario:
After the grid is loaded (binding to local data), in some cases, I need to apply the filters, paging, and selection from a previous state of the grid. If I do this inside the databound event, this will cause an infinte loop (as I've read and experience first-hand). How / where can I add the code from ApplyPreviousSettings (see below js code) so that it can work automatically?
E.g. of scenario in cause.
When on page "Users\Index" filter the grid (filterMode = row), change page (if necessary), and select an item.
Click on Edit (which redirects the edit page for the selected user) - at the point of leaving the "Users\Index" , I save in localstorage the grid's state (not all of it - only filter, paging and selection)
When clicking on Save or Cancel, the Index page (with the grid) will be displayed AND it is at this time that I want to "restore" the grid according to the data in the localstorage.
I've attached screenshots for the above scenario and a video.
The grid looks like this:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Title("#= Id #").Hidden(true).HtmlAttributes(new { id = "#= Id #" });
columns.Bound(p => p.FirstName).Title(Resource.Firstname).Filterable(f => f.Cell(c => c.Operator("Contains").ShowOperators(false).Template("EnableAutoFiltering")));
columns.Bound(p => p.Name).Title(Resource.Lastname).Filterable(f => f.Cell(c => c.Operator("Contains").ShowOperators(false).Template("EnableAutoFiltering")));
columns.Bound(p => p.EmailAddress).Title(Resource.Email).Filterable(f => f.Cell(c => c.Operator("Contains").ShowOperators(false).Template("EnableAutoFiltering")));
columns.Bound(p => p.CompletelyEquiped).Title(Resource.CompletelyEquipped)
.ClientTemplate("<div style='text-align: center;'><input type='checkbox' value='#= CompletelyEquiped #' disabled='disabled' " +
"# if (CompletelyEquiped) { #" +
"checked='checked'" +
"# } #" +
"/> </div>").Filterable(filterable =>
filterable.Messages(m => m.IsFalse(Resource.No_UserIndex))
.Messages(m => m.IsTrue(Resource.Yes_UserIndex)));
columns.Bound(p => p.BusinessUnit).Title(Resource.BusinessUnit_UserCreate).Filterable(f => f.Cell(c => c.Operator("Contains").ShowOperators(false).Template("EnableAutoFiltering")));
columns.Command(c => c.Destroy());
})
.ToolBar(toolbar =>
{
toolbar.Template(@<text>
<div class="toolbar">
<a href="@Url.Action("Create", "User")" class="k-button k-button-icontext" id="CreateButton"><span class='k-icon k-add'></span>@Resource.Create</a>
@Html.Kendo().Button().Name("EditButton").Content(Resource.Edit).Events(e => e.Click("EditClick")).SpriteCssClass("k-icon k-edit")
</div>
</text>);
})
.HtmlAttributes(new {style = "width: 125%;"})
.Pageable(pageable => pageable.Input(true).Numeric(false))
.Sortable()
.Events(e => e.DataBound("CustomizeFilterMenu"))
.Selectable(s => s.Mode(GridSelectionMode.Single))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(model => model.Id(p => p.Id))
.PageSize(10)
.Destroy("Delete", "User")
))
Javascript:
function EnableAutoFiltering(args) {
args.element.css("width", "90%").addClass("k-textbox").keydown(function (e) {
setTimeout(function () {
$(e.target).trigger("change");
});
});
}
function EditClick() {
var grid = $('#Grid').data("kendoGrid");
var selectedItem = grid.dataItem(grid.select());
if (selectedItem == null) {
alert("Please select row!");
} else {
if (window.location.pathname.endsWith("Index")) {
window.location = "../User/Edit/" + selectedItem["Id"];
} else {
window.location = "../" + window.location.pathname.split("/")[1] + "/User/Edit/" + selectedItem["Id"];
}
}
}
function ApplyPreviousSettings() {
var gridOptions = localStorage["kendo-grid-options"];
if (gridOptions === "null" || gridOptions === undefined) {
} else {
var grid = $("#Grid").data("kendoGrid");
var state = JSON.parse(gridOptions);
grid.dataSource.filter(state.filter);
grid.pager.page(parseInt(state.page));
var row = $("#Grid").find("tbody>tr>td[id= " + state.selectedUserId + "]").parent();
grid.select(row);
}
}
function CustomizeFilterMenu(args) {
var parents = $(":radio").parent();
if (!$(parents[0]).hasClass("RadioButtonFilterStyle")) {
$(parents[0]).addClass("RadioButtonFilterStyle");
}
}
window.onbeforeunload = function (e) {
if (e.target.activeElement.id === "EditButton" || e.target.activeElement.id === "CreateButton") {
var grid = $("#Grid").data("kendoGrid");
var dataSource = grid.dataSource;
var state =
{
page: dataSource.page(),
filter: dataSource.filter(),
selectedItem : grid.dataItem(grid.select()),
selectedUserId : grid.dataItem(grid.select()).Id
};
localStorage["kendo-grid-options"] = kendo.stringify(state);
} else {
localStorage["kendo-grid-options"] = null;
}
};
$(document).ready(function () {
$("#KendoGrid").removeAttr("hidden");
kendo.ui.progress($("KendoGrid"), false);
});
Important things to note:
Under the grid (as seen in the screenshots) there is a button which does (if I click it manually) exactly what I need to do automatically (the button with text: "ceva") - the button calls the js method ApplyPreviousSettings.
Also, here is a link to a video I've recorded, that I hope will clarify even further what I want to do.
https://www.dropbox.com/s/14wb1vuz76sr3st/sampleVideo2.zip?dl=0
Thank you.
Vlad