Date formatting on Kendo Grid Group Header - kendo-grid

I need to Group a Kendo Grid for every Month data. i am getting date in ISO format as given below.
2020-03-02T00:00:00
This is the column binding and data source grouping
column binding.
columns.Bound(z => z.MonthDisplay).Title("").Hidden(true).Format("{0:MMMM yyyy}");
data source binding with grouping
.DataSource(dataSource => dataSource
.PageSize(10)
.Group(groups => groups.AddDescending(t => t.MonthDisplay))
.Read(read => read.Action("AllData", "Common"))
)
The grouping is working properly. But my problem is the group heading is not formatting in MMMM yyyy format. It is showing as Month: 2020-03-02T00:00:00. I need to display header as Month: March 2020

I found the solution for this. I added a GroupHeaderTemplate as given below:
.columns.Bound(z => z.MonthDisplay).Title("").Hidden(true).ClientGroupHeaderTemplate("#= kendo.toString(kendo.parseDate(value.split('T')[0]), 'MMMM yyyy') #");

Related

Yii2 Boostrap period picker

I'm using Yii2 and I would like to have the following things:
A dropdown with "ranges" as items (week, full week, week-end, etc.) (done)
A RangePicker that based on the chosen range will:
allow only some days as the startDate (ex: week = mondays; week-end = saturdays)
will automatically select the end date based on the start date (ex: week: monday to friday; full week: monday to sunday; week-end: saturday to sunday, etc.)
For the dropdown, it's fine. But for the DateRangePicker, I started using Krajee DateRangePicker and
I do not find a callback for "onStartDateSelected" (I only saw a callback that is called when the range is selected, but not for individual start date or end date)
I do not see a "setStopDate" function
I do not see how to dynamically change the available days of weeks
I see that we can have a set of predefined periods like "last 7 days", "this month", etc. But this is not what I want. I want the user be able to select the start date but automatically calculate the end date based on what the user has set.
(I'm new in web dev, so please if you find anything that I could improve in my question, don't be afraid to share it)
You can use the following to accomplish the task:
Use the following library:
use kartik\date\DatePicker;
Use the following code in view:
<?php
$layout3 = '<span class="input-group-addon">From Date</span>
{input1}
<span class="input-group-addon">To Date</span>
{input2}
<span class="input-group-addon kv-date-remove">
<i class="glyphicon glyphicon-remove"></i>
</span>';
$previousDay = strtotime('-7 day', strtotime(date('d-M-Y'))); //Set as per your requirement[![enter image description here][1]][1]
echo DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'name' => 'startDate',
'value' => date('d-M-Y', $previousDay),
'name2' => 'endDate',
'value2' => date('d-M-Y'),
'separator' => '<i class="glyphicon glyphicon-resize-horizontal"></i>',
'layout' => $layout3,
'pluginOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy'
]
]);
?>

kendo grid date column format after filtering

I have a kendo MVC grid that has a bound column like below
columns.Bound(c => c.CreatedDate).Format("{0:M/d/yyyy h:mm tt}").Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains"))).Format("{0: MM/dd/yyyy HH.mm.ss}");
the column formats fine when first loading the view:
06/22/2017 15.02.00
but i have some buttons which use AJAX to post back and get back filtered data and when re-populating the grid the column looks like this:
/Date(1498161720000)/
Any help?
First off, you have two seperate .Format tags with different formats specified, which is probably causing some problems. Pick which one you want to use and try just removing the other.
If that doesn't solve the problem, I would try declaring the format using data annotations. In your model, try adding this line above the declaration of CreatedDate:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:M/d/yyyy h:mm tt}")]
and then remove .Format from your column binding.
i.e. change
columns.Bound(c => c.CreatedDate).Format("{0:M/d/yyyy h:mm tt}").Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
to
columns.Bound(c => c.CreatedDate).Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
and make sure you include the
using System.ComponentModel.DataAnnotations;
line at the top of your model if you don't already have it.

DateType and various formats

I have DateType. For example for saving foundation of some band to our database.
->add('founded', DateType::class, [
'label' => 'Founded',
'widget' => 'single_text',
'required' => false
])
There is unknown full date sometimes. There can be only a year and month known, or just a year without the day and month. But if I fill an incomplete date to this HTML5 input, nothing is saved and I have HTML5 error.
How is it possible to parse full date, year and month or just year with DateType and HTML5 input? Or is there any other alternative and clean solution?

Cakephp 3.0 I would like to include a Year input field with a drop down, but it is inputing as an array

I have a Year field in a form and I am using FormHelper.
echo $this->Form->input('year', [
'type' => 'year',
'minYear' => date('Y')-10,
'maxYear' => date('Y')
]);
The table file validator looks like:
->add('year', 'valid', ['rule' => 'numeric'])
->allowEmpty('year')
I have a very similar input in another app that seems to work fine. I set the MySql column to int(5) to match what I had working elsewhere.
Checking debugkit it shows the "year" input as an array while the other inputs are strings. If I remove the validation rule it throws an illegal array to string conversion, so I assume this is where the error is.
Any help is greatly appreciated.
I have just tested with your above code and it is working fine for me. Try to delete the cache and check it once more.
Creates a select element populated with the years from minYear to maxYear. Additionally, HTML attributes may be supplied in $options. If $options['empty'] is false, the select will not include an empty option:
empty - If true, the empty select option is shown. If a string, that
string is displayed as the empty element.
orderYear - Ordering of
year values in select options. Possible values ‘asc’, ‘desc’. Default
‘desc’ value The selected value of the input.
maxYear The max year to
appear in the select element.
minYear The min year to appear in the
select element.
Try this one:
<?php
echo $this->Form->year('exp_date', [
'minYear' => date('Y')-10,
'maxYear' => date('Y'),
'id' => 'cc-year',
'class' => 'form-control',
'empty' => false,
'orderYear' => 'asc'
]);
?>
Official Documentation: CookBook - Creating Year Inputs

Formatting date field in Sinatra form

I've got a form in Ruby/Sinatra where a date field is displayed:
%input{:type => "date", :name => "due_date", :value => #m.due_date}
On-screen, the form field presents as day-month-year (e.g. 23-11-2012).
I'd like the field content to be displayed as year-month-day (e.g. 2012-11-23).
Suggestions?
Try:
#m.due_date.strftime("%Y-%m-%d")
Take a look at http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime