I'm using kendo UI for my solution like in code below
<div id="myGrid" data-role="grid"
data-bind="source: viewModel"
data-sortable="true"
data-pageable="true"
data-filterable="true"
data-resizable="true"
data-editable = "incell"
data-selectable="true"
data-columns='[
{ field: "Name", title: "Name" },
{ field: "StartDate", title: "Start date", format: "{0:dd/MM/yyyy}"},
{ field: "EndDate", title: "End date", format: "{0:dd/MM/yyyy}"},
{ field: "ClosingDate", title: "Closing date", format: "{0:dd/MM/yyyy}"}]'
data-toolbar ='[{name:"create"},
{name:"save"}]'>
</div>
Fields in viewModel have "date" type.
Let's say I'm choosing Start date as 16/05/2014 and after that I'm saving changes. But after updating i see that Start date is 15/05/2014. And it happens with each date cell in grid.
Why date is less than i was chose.
Is there a way to solve this problem?
Refer to the answer given here: javascript Date.parse
I assume that the issue is caused by the browser you are using. I had a lot of trouble with date formatting in IE. I found that creating dates in Chrome or Firefox gave me exactly what I wanted, but in IE any format other than MM/dd/yyyy when creating or parsing a date gave the incorrect date in the Date object once parsed.
My suggestion is the same as the answer I linked to: instead of using the 'format' field of the column, use a template and parse it yourself.
data-columns='[
{ field: "Name", title: "Name" },
{ field: "StartDate", title: "Start date", template: "# parseDate(StartDate) #"},
{ field: "EndDate", title: "End date", template: "# parseDate(EndDate) #"},
{ field: "ClosingDate", title: "Closing date", template: "# parseDate(ClosingDate) #"]'
Then have your parseDate(date) function:
function parseDate(date) {
if (date == null) return '';
//using the .slice() method keeps the leading '0' if MM or dd is single digit
var rtn = ('0' + date.Date()).slice(-2) + '/' +
('0 + (date.Month() + 1)).slice(-2) + '/' +
date.FullYear();
return rtn;
}
Related
I wrote such schema for my date field:
StartDate: { type: "date", format: "{0:dd/MM/yyyy}" }
and a column definition:
{
field: "StartDate",
title: "Start Date",
template: '#= StartDate!=null ? kendo.toString(StartDate, "dd/MM/yyyy"): " " #',
width: 100
}
But I still see dates in format MM/dd/yyyy in datepicker during edition:
And if I try to write date manually in dd/MM/yyyy format I see:
Try adding a format field, like this:
columns: [{
field: "StartDate",
format: "{0: dd/MM/yyyy}"
// ...
}]
Setting culture is solved this issue
kendo.culture("en-GB")
I want to access to data row in kendo ui grid column command template ,but not found solution to resolve this request.
<script>
$("#grid").kendoGrid({
columns : [{
field : "firstname",
title : "First Name"
}, {
field : "lastname",
title : "Last Name"
}, {
field : "cellphone",
title : "Cell Phone"
}, {
field : "deskphone",
title : "Desk Phone"
}, {
field : "emailaddress",
title : "Email Address"
},
{
command : [
{
name: "note",
text: "note",
template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>",
imageClass: "fa fa-comment-o",
click: note_Clicked
}
]
});
</script>
i want to access to ID value from data of row in column command template as : #: rowData.ID #
template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>"
How to resolve this solution?
I don't think you can do it the way you are. I think you don't have access to the row data in that manner.
If you replace your rowData.ID with a function call instead, the function only executes twice, not once for every rendered row, which means the template is only "executed" during grid initialization.
I found this Telerik forum post that talks about this: http://www.telerik.com/forums/accessing-row-data-in-a-command
Where it is suggested that you use the Grid's dataBound event to change the text on the buttons and they provided a link to a demo Dojo.
Here is a link to a demo where I took the dojo from the forum post and slightly modified the dataBound handler to use the Id from the dataItem to dynamically changed the text on the button.
http://dojo.telerik.com/#Stephen/oVuCo
I'm not sure how else to do it.
I had the same problem. The solution I came to is below.
Instead of column command you can use simple column template where the data are accessible. Like that:
{
title: "Status", width: "140px",
template: (item) => {
if (item.Status == 'Outstanding') {
return "<a class='ignore-outstanding' >Outstanding</a>";
} else
return item.Status;
}
},
And add your click handler in dataBound handler like that:
dataBound: () => {
var grid = $(gridSelector).data("kendoGrid");
$(gridSelector + cellSelector).click((e) => {
e.preventDefault();
var dataItem = grid.dataItem($(e.currentTarget).closest("tr"));
alert(dataItem.YourField);
});
},
try this one
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
id: "Id",
fields:{
Id: {type: "number"},
firstname: { type: "string"},
lastname: { type: "string"},
cellphone: { type: "string"},
deskphone: { type: "string"},
emailaddress: { type: "string"}
}
}
}
},
columns : [{
field : "firstname",
title : "First Name"
}, {
field : "lastname",
title : "Last Name"
}, {
field : "cellphone",
title : "Cell Phone"
}, {
field : "deskphone",
title : "Desk Phone"
}, {
field : "emailaddress",
title : "Email Address"
},
{
command : [
{
name: "note",
text: "note",
template: "<a class='tds-grid-button k-button k-grid-#=name#' title='#=name#'>
#=Id# <i class='fa fa-comment-o'></i></a>"
}
]
});
</script>
Note-
in place of #=Id# put the primary field you want to set in kendo grid.
i think you have model in kendo grid datasource.
Tanks,
i find my solution to resolve it.
you can use dataBound event of kendo ui grid as follows:
$("#grid").kendoGrid({
columns : [{
field : "firstname",
title : "First Name"
}, {
field : "lastname",
title : "Last Name"
}, {
field : "cellphone",
title : "Cell Phone"
}, {
field : "deskphone",
title : "Desk Phone"
}, {
field : "emailaddress",
title : "Email Address"
},
{
command : [
{
name: "note",
text: "note",
template:"<a class='tds-grid-button k-button k-grid-#: name #' title='#: text #'> #: rowData.ID # <i class='fa fa-comment-o'></i></a>",
imageClass: "fa fa-comment-o",
click: note_Clicked
}
],
dataBound: function () {
var grid = this;
var model;
grid.tbody.find("tr[role='row']").each(function () {
rowData = grid.dataItem(this);
rowData.ID
rowData.Name
//and more and more
}
}
});
I'm using a kendo grid to display the data. When I filter on the date field specifying a date value (equals) then it works fine. But when I use the before or after conditions in the filter, it filters the data incorrectly.
Also sorting on the date field does not sort it properly. Any help would be greatly appreciated. FYI: I used the moment.js to format the data in dd/mm/yyyy format.
Here is the code snippet with the data:
$("#testgrid").kendoGrid({
change:onChange,
dataSource: {
data: [
{"No":"27691","ClientName":"ABC","ExpiryDate":"2015-03-14T00:00:00Z"},
{"No":"27691","Name":"DEF","ExpiryDate":"2016-03-22T00:00:00Z"},
{"No":"27691","Name":"ABC","ExpiryDate":"2015-02-28T00:00:00Z"},
{"No":"27691","Name":"ABC","ExpiryDate":"2011-07-03T00:00:00Z"},
{"No":"27691","Name":"ABC","ExpiryDate":"2015-07-31T00:00:00Z"},
{"No":"27691","Name":"ABC","ExpiryDate":null},
{"No":"27691","Name":"ABC","ExpiryDate":"2012-04-30T00:00:00Z"}
],
schema: {
model: {
fields: {
No: { type: "string" },
ExpiryDate: {
type: "date",
parse: function(inputdate) {
var dtval = moment(inputdate).format('DD/MM/YYYY');
if (dtval == "Invalid date")
return "";
else return dtval;}
},
Name: { type: "string" }
}
}
},
pageSize: 20
},
height: 550,
selectable: "single row",
allowCopy: true,
resizable: true,
groupable: true,
sortable: true,
filterable: {
mode: 'row',
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
pageable: true,
columns: [
{ field: "No", title: "Number", filterable: { cell: { showOperators: true, operator: "contains" } } , width: 150 },
{ field: "Name", title: "Name", filterable: { cell: { showOperators: true} }, width: 150 },
{ field: "ExpiryDate", title: "Expiry Date",
format: "{0:dd/MM/yyyy}", filterable: {
cell: {
template: function (args) {
args.element.kendoDatePicker({
format: "{0:dd/MM/yyyy}"
});
}
}}
, width: 150 }
]
});`
Interestingly, I've been struggling with an issue related to the filter field its self; I couldn't change the format of the date...
Your section of code for the "ExpiryDate" field helped solve my problem!
{ filterable: { cell: { template: function (args) { args.element.kendoDatePicker({ format: "{0:dd/MM/yyyy}" }); }
}}
Thought it might be useful to highlight this for others.
Removing the parse setting in the schema probably solves the sorting problem. On the filtering, perhaps the "problem" is that your dates are in UTC, but Kendo displays them in your browser's local time, and you need to deal with time.
I am in US Central Daylight Time (CDT), so 2015-03-14T00:00:00Z shows as 13/03/2015 in the grid. If I use an "equals" filter with 13/03/2015 then I get no results in the grid. Same thing - no result - with 14/03/2015. If I change the datepicker template format to dd/MM/yyyy HH:mm:ss and filter by equals 13/03/2015 19:00:00 then I get that entry, as expected.
Thus in order to use "equals" you must have (a) the time component and (b) remember the conversion of local to UTC.
Demo in Kendo Dojo
I am using Kendo UI to render data in grid format. In grid there is a column of status which can have values like completed, error, in progress etc. Now to make it more convenient I want to represent it using images. In case of single icon I can use below code in COLUMNS array:
columns:[
{
field: "oper",
title: "Operation"
},
{
field: "exedate",
title: "Date"
},
{
field: "status",
title: "Status",
template: '<img src="/resources/icons/user_green.png"/>
}]
But now, how to represent multiple icons and that to with condition based on status value that I am not able to find out?
You can have control over the template if you pass a function.
{
field: "status",
title: "Status",
template: function(dataRow){
var icon = 'red.png'
switch(dataRow.status){
// Assign here the icon as you please.
}
return '<img src="/resources/icons/' + icon + '"/>';
}
}
Another solution is to define CSS classes to the different statuses.
.statusicon.good
{
background: url('green.png')
}
.statusicon.bad
{
background: url('red.png')
}
And then just render the css class in your template.
{
field: "status",
title: "Status",
template: '<div class="statusicon #: status #"></div>
}
First, I know how to exclude a field by marking it 'editable: false' in the kendo data source.
I added a column with a button to the Kendo UI grid to open a window for a file upload. This column is not in the datasource! However, the column is now also displayed in the popup editor as a tetxtbox with 'File Upload' as a label (that is the column header name also as you can see in the screenshot).
How can I exclude/hide this column in the popup editor?
I am using Kendo UI version: "2014.2.716"
Thanks for your help!
Here is how I added the column to the grid, see the last line:
columns: [
{ field: "Id", hidden: true },
{ field: "Name", title: ........ },
{ field: "EnteredBy", title: "Entered by", hidden: true },
{ field: "UpdatedOn", type: "date",.....},
{ field: "UpdatedBy", title: "......},
{ command: ["edit", "destroy"], title: "Action", width: "80px" },
{ field: "Upload", title: "File Upload", width: "80px", template: '<button class="k-button" onClick="uploadFiles(#=Id#)">Upload<br/>Files</button>' }
],
and here is a screenshot that shows the column 'File Upload' with the button 'Upload File' in each cell in the grid-column.
This is the screenshot from the popup editor with the field that I would like to hide.
I think you should make that extra column a custom command instead of specifying a "field" for it.
Something like:
columns: [
...
{
command: { text: "Upload", click: uploadFiles},
title: "File Upload",
width: "80px"
}
]
The uploadFiles function would then get passed a click event, from which it can get to the element that was clicked. You can add a data-id attribute to the row to get its Id from in the uploadFiles function, as they do in the demo linked above.