I want to include kendo dropdownlist into my grid.
Everything's going to be fine except one thing.
When i want to "Add Record" with default kendo create toolbar, i can't bind first value fetched from dropdownlist datasource.
Datasource works fine. Dropdownlist works fine too.
If I choose anything from dropdownlist manually, everything works fine.
$scope.mainGridOptions = {
dataSource: {
transport: ...
schema: ...
},
batch: false,
...
toolbar: ["create"],
columns: [
...,{
field: "location_id",
title: "Location",
editor: function(container,options){
var input = $('<input/>');
input.attr('name',options.field);
input.appendTo(container);
input.kendoDropDownList({
autoBind: true,
dataTextField: "text",
dataValueField: "value",
dataSource: locationsDataSource,
index: 0,
});
}
},
...
]
};
I tried this too. except "index", i tried to manually select first item from dataSource. Visually it works fine. Even with Third item selected too, but when i click "Update", data isn't bounded.
input.kendoDropDownList({
autoBind: true,
dataTextField: "text",
dataValueField: "value",
dataSource: locationsDataSource,
dataBound: function(e){
this.select(0);
}
});
Anyone?
So, i found the solution.
It's seem to be a bug of Kendo DropDownList.
I'm bounding it manually after dataSource load from dropdown dataBound event.
Here we go:
editor: function(container,options){
var input = $('<input/>');
input.attr('name',options.field);
input.attr('data-bind','value:' + options.field);
input.appendTo(container);
input.kendoDropDownList({
autoBind: true,
dataTextField: "text",
dataValueField: "value",
dataSource: locationsDataSource,
index: 0,
dataBound: function(){
options.model[options.field] = this.dataItem().value;
}//end databound
});//end dropdownlist
}//end editor
Related
I have an existing grid creating in Kendo UI for Jquery. I want to put a static drop down/select box in the first field/cell of the grid on each row. When I do it shows up as "undefined".
Most of the examples I see on her and the Telerik site use an editor. In my case the drop down is static. Once they click on an item they will be redirect to another page to do something. At the moment I just want to get the drop down to show up with hard coded options.
jQuery(function($){
"use strict";
var grid = $("#grid").kendoGrid(){
....
columns: [{
field: "my_links",
title: "My Links",
template: "#=getMyLinks(DATA.user_id)#"
},{
....
}_.data("kendoGrid");
function setGridData(){
....
});
grid.setDataSource(dataSource);
}
setGridData();
});
function getMyLinks(user_id){
$('<input id="my_links" name="my_links/>')
.kendoDropDownList{[
dataSource: [
{ id: 1, name: "View" },
{ id: 2, name: "Create },
{ id: 3, name: "Delete"}
],
dataTextField: "name",
dataValueField: "id"
});
}
I would expect a drop down in the
You should provide DOM element for drop down widget in columns.template field and then initialize all widgets in dataBound event.
$("#grid").kendoGrid({
columns: [{
field: "my_links",
title: "My Links",
template: "<input id="my_links" name="my_links/>"
}],
dataBound: function (){
getMyLinks(DATA.user_id);
}
}).data("kendoGrid");
I've used the hierarchical kendo for showing my data, I mean each row has a child which contains a grid of rows' details,my kendo should appear based on the data that user enter in inputs and after click on a button , it works well for the first time but if user change the inputs' data and click the button again, the kendo does not show the grid of details it just show me my parent grid but if the user refresh the page and then change the data and click the button it works fine. after a lot of search I couldn't find the reason.can anyone help me
var grid;
var createGrid = function () {
grid = $("#mygrid").kendoGrid({
dataSource: {
data: schema.PNR_item,
schema: {
hasChildren: true,
model:{
fields:fields,
}
},
pageable: true,
height: 550,
pageSize: 6,
serverPaging: true,
serverSorting: true,
//columns
},
height: 600,
sortable: true,
pageable: true,
scrollable: true,
resizable:true,
columns: columns,
detailTemplate: '<div class="grid" ></div>',
detailInit: function (e) {
e.detailRow.find(".grid").kendoGrid({
dataSource: e.data.Details,
columns: details_columns,
schema:{
model:{
fields: details_fields
}
}
});
},
}).data("kendoGrid");
}//end of createGrid function
createGrid();
I am currently working with Kendo UI and am trying to data bind my Kendo observable to my drop down list. My drop down list is customized and is created inside of a Kendo editing popup object. I used a simple approach of just calling the editor in my columns and creating a function that creates a drop down list in that object. Now I am able to data bind with out an issue in my HTML file, however I am finding it difficult to do the same with my current approach.
Currently I am filling up the grid with data, I am able to populate the grid with the client name and client number, but the client type is not being posted. I assume is the failure to appropriately data-bind.
This is my Kendo observable
var viewModel = kendo.observable({
client: {
clientName: "",
clientNumber: "",
clientType: "",
},
dropdownlist: ["HCC", "Tax", "Audit", "Advisory"],
});
This is my Kendo Grid
$("#grid").kendoGrid({
dataSource: client,
toolbar: ["create"],
columns: [{
field: "clientName",
title: "Client Name",
},
{
field: "clientNumber",
title: "Client Number",
},
{
field: "clientType",
title: "Client Type",
editor: categoryDropDownEditor,
}
],
editable: "popup",
})
And this is my customized function which I am having issues data binding.
function categoryDropDownEditor(container) {
$('<input data-role="dropdownlist" data-bind="source: dropdownlist , value: client.clientType">')
.appendTo(container)
.kendoDropDownList({
optionLabel: "Engagement Types",
dataSource: viewModel.dropdownlist,
});
}
replace value: client.clientType to value: clientType:
function categoryDropDownEditor(container) {
$('<input data-role="dropdownlist" data-bind="source: dropdownlist, value: clientType">')
.appendTo(container)
.kendoDropDownList({
optionLabel: "Engagement Types",
dataSource: viewModel.dropdownlist,
});
}
I have the following code in a
jsfiddle example
var remainingFalilities = [
{"Text":"Facility 1","Value":"1"},
{"Text":"Facility 2","Value":"2"},
{"Text":"Facility 3","Value":"3"},
{"Text":"Facility 4","Value":"4"},
{"Text":"Facility 5","Value":"5"},
{"Text":"Facility 6","Value":"6"},
{"Text":"Facility 7","Value":"7"},
];
var ds = new kendo.data.DataSource({
data: remainingFalilities
});
var selectedFacilities = [
{"Text":"Facility 8","Value":"8"},
{"Text":"Facility 9","Value":"9"}];
var dataSource = new kendo.data.DataSource({
data: selectedFacilities,
batch: false,
pageSize: 20,
schema: {
model: {
id: "Value",
fields: {Text: { type: "string" }}
}
}
});
$("#FacilityGrid").kendoGrid({
dataSource: dataSource,
autoBind: true,
editable: { mode: "inline" },
sortable: true,
selectable: true,
toolbar: ["create"],
columns: [
{ command: ["destroy", "edit"], title: " ", width: "250px" },
{ field: "Text", title: "Facility Name", editor: facilityDropDownEditor },
]
});
function facilityDropDownEditor(container, options) {
$('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: ds
});
}
The Problem is, when a user clicks "Add new record" it adds a new item with the facility name dropdown showing the 1st item in the list. If the user clicks "Update", it saves the record but blanks out the facility name. The reason is, there really isn't an item selected in the dropdown. I know this because the selected value is null when it is passed to my controller code. So, I really want to know how to either
Not show the first item in the list until the user actually selects it in the list OR
set the selected item to the first item in the list so the value will not be null when passed to my controller.
The answer for both ways would be even better.
To not showing the dropdown's items until user select them manually use optionLabel
function facilityDropDownEditor(container, options) {
$('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: ds,
optionLabel: "Select an item..."
});
}
OR
Use index to put initially selected item.
function facilityDropDownEditor(container, options) {
$('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: ds,
index : 1
});
}
One option, not listed among your proposals, is setting optionLabel that is displayed when the value is null.
$('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
.appendTo(container)
.kendoDropDownList(
{
autoBind: true,
dataSource: ds,
optionLabel:"Select Facility"
}
);
Your jsfiddle modified here
I am trying to filter my kendo Grid with a multiselect box. I have a grid with serverFiltering turned on with more or less this setup:
// this is in the grid configuration
columns: [
{
title: "Name",
width: 160,
field: mem_ORD_EditieTitel,
filterable: {
ui: multiSelect
}
}, ...
]
// and the function corresponding to the filterable option
function multiSelect(element)
{
var multi = element.kendoMultiSelect({
placeholder: "Select editions",
dataSource: remoteDataSource,
dataTextField: "mem_ORD_EditieTitel",
dataValueField: "mem_ORD_EditieTitel",
optionLabel: "--Select Value--"
}).data('kendoMultiSelect');
}
The problem is that when i select more than one value, the request only includes the first selected item. Is there anyway to fix this? Or does the kendo grid just doesnt feature this? For example:
filter[filters][0][field]:mem_ORD_EditieTitel
filter[filters][0][operator]:eq
filter[filters][0][value]:SomeTitle
filter[logic]:and
Thanks
When I use this definition:
element.kendoMultiSelect({
valuePrimitive: true,
dataSource: kendoDataSource,
dataTextField: textField,
dataValueField: valueField,
optionLabel: optionLabel
}).data("kendoMultiSelect");
Multiple values are posted to the server:
filter[filters][0][field] SubFunctionCode
filter[filters][0][operation] eq
filter[filters][0][value] ICT-2,ICT-3
filter[logic] and
page 1
pageSize 5
skip 0
take 5
The filter[filters][0][value] equals "ICT-2,ICT-3".
The next challenge is how to process the comma-separated value at the server-side. I do not have a solution for this issue...