Telerik Forums
UI for ASP.NET MVC Forum
1 answer
33 views

Is it possible to extend the Telerik MVC Grid toolbar to include custom commands? I'm looking to add my own functionality to the toolbar, and I'm wondering if there's a way to create a method within the toolbar command factory to generate buttons with specific functionality that I want to apply across all grids in my application.

For example, I have these three methods I have added using the toolbar template.


instead of using the template every time I would like to add custom command like save or excel.

Anton Mironov
Telerik team
 answered on 11 Mar 2024
0 answers
18 views

I'm trying to export a grid to Excel, and I have followed the Telerik example:

https://demos.telerik.com/aspnet-mvc/grid/excel-export?autoRun=true&theme=default-main

But what I cannot manage to do is to prevent a call to excel_export_read when clicking the Export to Excel button. In Chrome Devtools I can see that also the official Telerik example calls this method a second time when clicking, but I was under the impression that the component would try to create the excel file client side. Is this not possible?

Here is my code:

 

@(Html.Kendo().Grid<CampaignSimulationResult>()
    .Name("SimulateResult")
    .ToolBar(tools => tools.Excel())
    .DefaultSettings()
    .Columns(column =>
        {
            column.Bound(m => m.Region).HeaderHtmlAttributes(new { style = "text-align:center" })
                .HtmlAttributes(new { style = "text-align: center" });
            column.Bound(m => m.ParameterID).Format("{0:##,#}").HtmlAttributes(new { style = "text-align: right" }).HeaderHtmlAttributes(new { style = "text-align:center" });
            column.Bound(m => m.Parameter).HtmlAttributes(new { style = "white-space: nowrap;" }).HeaderHtmlAttributes(new { style = "text-align:center" });
        }
    ).Excel(excel => excel
        .FileName("Kendo UI Grid Export.xlsx")
        .Filterable(true)
    )
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("ExcelExportRead", "Campaign", new RouteValueDictionary { { "area", "Admin" } }))
    )
)


Snorre Garmann
Top achievements
Rank 1
 asked on 05 Mar 2024
1 answer
21 views

I've been working with the Kendo DatePicker UI component and I really like the masking and validation it provides if a user wants to manually enter a date when DateInput() is applied. However, it also adds segmentation which means a user either needs to click or use arrow keys to move on to edit other parts of the date like month, day or year. If I remove DateInput() there is no more segmentation, but also no validation or masking. Is there a way to keep validation and masking in the date input field without the segmentation and keep the date picker functionality? My other option is to remove .DateInput() along with the messages and manually apply validation and masking, but if there is a solution within the component itself, that would be ideal. Below is what we currently have.

                                                       @(Html.Kendo().DatePicker()
.Format(Model.DateMask)
.Name("DateStart")
.DateInput()
.Messages(m => m.DateInput(d => d.Day("__")))
.Messages(m => m.DateInput(d => d.Month("__")))
.Messages(m => m.DateInput(d => d.Year("____")))
.Culture(UICulture)
.Footer(false)
                          )

Anton Mironov
Telerik team
 answered on 05 Mar 2024
0 answers
47 views

From https://www.telerik.com/download/custom-download# I tried to download the latest version 2024.1.130 kendo.custom.min.js file in order to upgrade the kendo plugin  from Kendo UI 2022.1.412 version to the latest. 
I use Asp.Net MVC and I have a custom bundler where I reference all the js files like this

 bundles.Add(new ScriptBundle("~/bundle/kendo").Include( "~/Scripts/kendo/kendo.custom.min.js"));   

Then in Razor Layout page I register bundles like this

@Scripts.Render("~/bundle/kendo")

but whenever I run the application I always get a NullReferenceException at the line that registers the bundle with the message "No object reference is set to an object instance."

Whenever I downgrade the kendo version or return to the previous one the application runs properly.

Any ideas why is this happening? Would you please help me solve this issue? 

Thanx in Advance.

AGGELIKI
Top achievements
Rank 1
Iron
 asked on 29 Feb 2024
1 answer
27 views

Can we change the starting day of the week from Sunday to Monday? i.e. MO, TU, WE, TH, FR, SA, SU

Or Sunday to Saturday? i.e. SA, SU, MO, TU, WE, TH, FR

Instead of the current: SU, MO, TU, WE, TH, FR, SA

Mihaela
Telerik team
 answered on 28 Feb 2024
1 answer
15 views
Is it possible to make it so if a user clicks a day it selects the whole week, like clicking the week number does? Then is it also possible to capture multiple selected weeks (not necessarily concurrent weeks or in the same month), even if all the dates in those selected weeks are the output that would be fine
Ivan Danchev
Telerik team
 answered on 28 Feb 2024
0 answers
26 views

My page has a combo box. As the user selects an ID from the dropdown list, the page populates with information corresponding to the entry. It is an AJAX bound combo box. I am trying to make the combo box get auto populated with an ID from my query string on initialization. 

I've tried setting the .Value field of the combo box. This works to automatically select the correct ID and populate the rest of the page, but only when the ID exists in the data source. My AJAX call returns data based on the partial/full ID passed in, and a list of a few most recent ID's if no input ID is specified. 

I believe this will work if the ID exists in the data source prior to setting the value field of the combo box. But for that to happen, the combo box must use the ID from the url to fetch the data source, similar to what happens when a user manually types that ID into the combo box. However, I am struggling to figure out how to pass in a specific ID when the combo box is responsible for making the AJAX call. 

I would appreciate any advice or other suggestions to getting the intended behavior.

Eugenia
Top achievements
Rank 1
 asked on 27 Feb 2024
0 answers
31 views

I am using a Kendo.Filter object like the following to filter results in a Kendo Grid:

@(Html.Kendo().Filter<CustomPersonClass>() .Name("personFilter") .DataSource("peopleDS") .ApplyButton(false) .Fields(f => {

f.Add(p => p.LastName).Label("Last Name");
         f.Add(p => p.FirstName).Label("First Name");
         f.Add(p => p.MiddleName).Label("Middle Name");

f.Add(p => p.StartDate).Label("Start Date").Operators(o => o.Date(d => d.Eq("Is equal to").Gte("Greater than equal").Lte("Less than equal"))); }) )

 I have helper code to handle the toolbar in my Kendo Grid like the following, :

@helper ToolbarTemplate()
{
    <button class="k-button k-button-solid k-button-solid-base" id="applyFilter"><span class="k-icon k-i-filter"></span>Apply Filter</button>
    <button class="k-button k-button-solid k-button-solid-base" id="clearFilter">Reset</button>
    <button class="k-button k-grid-excel k-button-solid k-button-solid-base"><span class="k-icon k-i-excel"></span>Export to Excel</button>
}

I also have some JavaScript in a function to apply the filter when the Apply Filter button is clicked, as seen here:

$("#applyFilter").click(function (e) {
    //e.preventDefault();
    var myFilter = $("#personFilter").getKendoFilter();
    localStorage["kendo-person-filter-options"] = kendo.stringify(myFilter.getOptions().expression);
    myFilter.applyFilter();
});

 

The problem I am having is if I enter an invalid Leap Year date (e.g. 2/29/2003, since 2023 didn't have a February 29th), I get no data back; however, if I enter a valid Leap Year (e.g. 2/29/2004), my Kendo Grid will show data.  Is there a way to validate the date that is being entered manually into a DatePicker field used for filtering?  That is, if I use the DatePicker, it will not show me 2/29/2003 as an option, but if I type in 2/29/2003 and click Apply Filter, it doesn't throw any kind of error about 2/29/2003 being invalid.

1 answer
20 views

Controls loading icon stretching fields

As you can see fields grow and shrink due the the loading icon right of the dynamic controls being larger than the control I believe

Is this a bug or something I can do to resolve

https://i.imgur.com/puFkDGl.gif

Eyup
Telerik team
 answered on 26 Feb 2024
0 answers
24 views

I use the following code to show the calendar:

<div class="section">
    <script id="event-template" type="text/x-kendo-template">
        <div class="item-template" title="#: title #">
            <div class="title">#: title #</div>
        </div>
    </script>
    <div class="daily-container">
        @(Html.Kendo().Scheduler<WaterFlowReadingModel>()
    .Name("Daily")
	.Events(e =>
	{
		e.Navigate("scheduler_navigate");
		e.DataBound("scheduler_databound");

	})
    .Date((DateTime)ViewBag.Month)
    .StartTime((DateTime)ViewBag.Month)
	.EventTemplateId("event-template")
    .Views(v =>
    {
        v.MonthView();
    })
	.DataSource(d =>
		d.Model(m =>
		{
            m.Id(f => f.Id);
            m.RecurrenceId(f => f.RecurrenceRule);
			m.Field(f => f.Title).DefaultValue("No title");
		}).ServerOperation(true)
		.Read(read => read.Action("GetMetricDaily", "Metric",
			new { type = 1, start = ViewBag.Month.AddMonths(-1), end = ViewBag.Month.AddMonths(1) }))
    ))
    </div>
</div>

Javascript:

    function scheduler_navigate(e) {
        var start = kendo.format('{0:d}', this.view().startDate());
        var end = kendo.format('{0:d}', this.view().endDate());

        $.ajax({
            url: "@(Url.Action("GetMetricDaily", "Metric"))",
            data: {
                start: start,
                end: end,
            }, success: function () {

                var scheduler = $("#Daily").data("kendoScheduler");

                scheduler.refresh();
            }
        });
    }

    function scheduler_databound(e) {
        var today = e.date;
        var scheduler = $("#Daily").data("kendoScheduler");
        var newDate = scheduler.date();
        console.log(newDate, today);
		$.ajax({
			url: "@(Url.Action("GetStatistics", "Metric"))",
			dataType: "json",
			data: {
				month: kendo.format('{0:d}', newDate),
            }, success: function (data) {
				//console.log(data);
				date = new Date(data.ReportingPeriod.match(/\d+/)[0] * 1);
                $("#TotalMonthlyDischargeVolume").val(data.TotalMonthlyDischargeVolume);
                $("#NumberOfDaysOfDischargeToSewer").val(data.NumberOfDaysOfDischargeToSewer);
				$("#MaximumDailyFlow").val(data.MaximumDailyFlow);
                $("#ReportingPeriod").val(kendo.toString(date, "Y"));
            }
        });
    };

The problem is that when I select a different month, no data at all is shown unless I select the current month again, which then shows current data.

Controller code:


        public ActionResult GetMetricDaily([DataSourceRequest] DataSourceRequest request, DateTime start, DateTime end)
        {
            using (var db = new DatabaseContext())
            {
                // Water flows
                var lastMonth = db.WaterFlows
                    .Where(w => w.TimeStamp > start && w.TimeStamp < end && w.TotalizerReading >= 1)
                    .Select(x => new WaterFlowReadingModel()
                    {
                        Title = x.TotalizerReading.ToString(),
                        Start = x.TimeStamp,
                        End = x.TimeStamp,
                        Id = x.Id,
                    }).ToList();
                
                // pH Readings
                var result = db.pHReadings.Where(w => w.TimeStamp > start && w.TimeStamp < end)
                    .GroupBy(o => EntityFunctions.TruncateTime(o.TimeStamp))
                    .Select(g => new
                    {
                        Date = g.Key,
                        Min = g.Min(o => o.pHValue),
                        Max = g.Max(o => o.pHValue),
                        Avg = g.Average(o => o.pHValue)
                    })
                    .ToList();
                
                var output = new List<WaterFlowReadingModel>();
                foreach (var item in result)
                {
                    var title = $"PH - Min: {item.Min:F} / Max: {item.Max:F} / Avg: {item.Avg:F}";
                    output.Add( new WaterFlowReadingModel()
                    {
                        Title = title,
                        Start = item.Date ?? DateTime.Today,
                        End = item.Date ?? DateTime.Today,
                        Id = 0
                    });
                }

                lastMonth.AddRange(output);
                return Json(lastMonth.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }
        }



Jason
Top achievements
Rank 1
Veteran
 asked on 26 Feb 2024
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?