Telerik Forums
UI for ASP.NET Core Forum
2 answers
413 views

Hi,

I have a grid that uses Popup editor. The model behind the grid has one property with Required attribute.

The application has to support multiple languages. All the grid and popup texts are translated except for the validation messages.

It seems that the template generated uses the english messages. 

"template":"\u003cdiv class=\"editor-label\"\u003e\u003clabel for=\"Name\"\u003eHersteller\u003c/label\u003e\u003c/div\u003e\u003cdiv class=\"editor-field\"\u003e\u003cinput class=\"k-textbox\" data-val=\"true\" data-val-required=\"The Hersteller field is required.\" id=\"Name\" name=\"Name\" value=\"\" /\u003e \u003cspan class=\"field-validation-valid\" data-valmsg-for=\"Name\" data-valmsg-replace=\"true\"\u003e\u003c/span\u003e\u003c/div\u003e"

Is this function as design. How can I get the language specific message for validations too?

Stefan
Telerik team
 answered on 03 Apr 2018
3 answers
963 views

I have a business requirement that I don't know how to quite handle using the grid.  I have set up inline batch editing on a grid for a customer.  One of the requirements is to do client side business logic to validate the data before allowing the Save Changes functionality to work. 

My grid is set up something like this

ColA    ColB    ColC    ColD

10           0         0           0

The requirement is that if any of those 4 columns has a value, all the columns must have a non-zero value. I'm not sure how to access the ids/values of  ColB, ColC, ColD so that I can do the comparison in the javascript.  When I took a look using firebug, each of those fields had a guid identifier (screenshot below).

The code I am playing around with is as follows 

//register custom validation rules
   (function ($, kendo) {
       $.extend(true, kendo.ui.validator, {
           rules: { // custom rules
               productnamevalidation: function (input, params) {
                   if (input.is("[name='operating_hrs']") && input.val() != "") {
                       input.attr("data-productnamevalidation-msg", "Product Name should start with capital letter");
                       if (input.val() != 24)
                       {
                           var input1 = $('input[data-bind="value:hrsepwr_hrs"]');
                           var input2 = input1.val();
                           alert(input2);
                           //alert($('#station_id').val());
                           return false;
                        }
                       //return /^[A-Z]/.test(input.val());
                   }
 
                   return true;
               }
           },
           messages: { //custom rules messages
               productnamevalidation: function (input) {
                   // return the message text
                   return input.attr("data-val-productnamevalidation");
               }
           }
       });
   })(jQuery, kendo);
Michael
Top achievements
Rank 1
 answered on 02 Apr 2018
2 answers
110 views

I cannot figure out how to override the overall container size of a Grid Editor. So I have the custom types in the ~/Shared folder and while they all show in edit mode they are many times to small in width.  Yet setting the style of the wrapper div the controls are in has no effect.  Is there a style I need to override in each view?

 

Thanks

Reid
Top achievements
Rank 2
 answered on 02 Apr 2018
1 answer
129 views

Hi,

 

I am planning to use tag helpers instead of this - 

 <select asp-for="Input.ReviewBank" asp-items="@(new SelectList(@Model.Banks,"BankBacisId","ReviewBankandCity"))" class="form-control" on></select>

but the documentation is available only for API or ajax call. Can you please point me towards achieving a filtered drop down from Model values on a Razor Page. 

Veselin Tsvetanov
Telerik team
 answered on 02 Apr 2018
1 answer
1.1K+ views

Hi,

I have 2 date pickers-

<div class=""><kendo-datepicker name="Input.ReviewStartDateTime" start="CalendarView.Month" depth="CalendarView.Year" format="yyyy/MM/dd" value="DateTime.Now" on-change="endChange"/> </div>

<div><kendo-datepicker name="Input.ReviewEndDateTime"  start="CalendarView.Month" depth="CalendarView.Year" format="yyyy/MM/dd" value="DateTime.Now" /></div>      

 

I am trying to change the value of Input.ReviewEndDateTime  picker to + 60 days  on change Input.ReviewStartDateTime picker -

        function endChange() {
            var startDatePicker = $("#Input.ReviewStartDateTime").data("kendoDatePicker"),
                startDate = this.value();
            console.log(startDate);
            if (startDate) {
                var endDate = new Date(startDate.getMonth() + 2);

                var endatepicker = $("#Input.ReviewEndDateTime").data("kendoDatePicker");
                endatepicker.value(startDate);
                endatepicker.trigger("change");
            }
        }

but I get the following error- 

Uncaught TypeError: Cannot read property 'value' of undefined

 

How can I change the date picker to 60 dates after theselected date from Input.ReviewStartDateTime

Stefan
Telerik team
 answered on 02 Apr 2018
2 answers
163 views

I am trying to create ChunkUploadController for Net Core 2 API Controller follow 

https://demos.telerik.com/aspnet-core/upload/chunkupload

but getting compilation error 

Error CS0144 Cannot create an instance of the abstract class or interface 'FileResult'

on the line 

FileResult fileBlob = new FileResult();

 

Could you guide me how to fix this error?

Thank you,

Vladimir

 

Dimitar
Telerik team
 answered on 30 Mar 2018
2 answers
1.6K+ views

Hi,

I have a razor page which is showing a grid, where the on-change is bound to a javascript function that loads a partial view using $.ajax into an element on the same page.
That partial view is using kendo htmlhelpers to construct certain elements.
Since these elements are initialized using kendo.syncReady(), those initialization functions are (obviously) put into the global scope.
This leads to a problem due to those initialization functions never get cleaned up as I can see while debugging in VS 2017.
There is a script block section in which those methods keep adding up each time i select another row which loads the related partial view.

any ideas how to prevent this or how to clean this up ?

Thanks in advance.

Tsvetina
Telerik team
 answered on 30 Mar 2018
1 answer
121 views

Is there a way to send back the number of rows affected on an updated with inline batch editing so that I can inform the users how many rows they have successfully updated?  I haven't been able to find anything on the web for the Kendo Grid that would help me out.  My cshtml file is

@{
        ViewData["Title"] = "Index";
}
@Html.AntiForgeryToken()
 
<h2>Index</h2>
 
@(Html.Kendo().Grid<FacilityDataManager.ViewModels.FDMError>
    ()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.ID).Hidden(true);//.Hidden(true);
        columns.Bound(c => c.ScadaDailyID).Hidden(true);
        columns.Bound(c => c.station_asset_id).Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Station Asset ID").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal;font-weight:700;" });
        columns.Bound(c => c.station_id).Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Station ID").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal;" });
        columns.Bound(c => c.error_type).Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Error Type").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.reading_date).Format("{0:MM/dd/yyyy}").Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Reading Date").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        //change the column below to a checkbox
        //columns.Bound(c => c.errorCorrected).ClientTemplate("<input type='checkbox' disabled='true' value='#= errorCorrected #' " + " # if (errorCorrected) { #" + "checked='checked'" + "# } #" + "/>" );
        columns.Bound(c=> c.operating_hrs).Title("Operating Hours").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.ttl_downtime_hrs).Title("Downtime Hours").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.hrsepwr_hrs).Title("Horsepower Hours").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.fuel_consumed).Title("Fuel Consumed").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.engine_starts_attempts).Title("Engine Start Attempts").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.engine_starts_failed).Title("Engine Start Failures").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.engine_starts_success).Title("Engine Start Successes").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.startup_duration).Title("Startup Duration").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.thruput_mmcf).Title("Throughput MMCF").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.avg_unit_rpm).Title("Average Unit RPM").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.oil_to_comp_cyl).Title("Oil Usage (Compressor)").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.oil_to_pwr_cyl).Title("Oil Usage (Engine)").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.oil_new_cc_hand).Title("Oil Usage (Manual)").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
        columns.Bound(c => c.blowdown_cnt).Title("Blowdown Count").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" });
    })
    .ToolBar(toolbar =>
    {
        toolbar.Save();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Sortable()
    .Filterable()
    .Pageable()
    .Scrollable(scrollable => scrollable.Height(700))
    .Reorderable(reorderable => reorderable.Columns(true))
    .Resizable(resizable => resizable.Columns(true))
    .ColumnResizeHandleWidth(20)
    .ColumnMenu()
    .Navigatable()
    .DataSource(dataSource => dataSource
    .Ajax()
    .Batch(true)
    .PageSize(20)
    .ServerOperation(false)
    .Events(events => events
        .Error("error_handler")
        .RequestEnd("refreshGrid")
    )
    //set the fields to non-editable here
    .Model(model =>
    {
        model.Id(p => p.ID);
        model.Field(p => p.ID).Editable(false);
        model.Field(p => p.station_id).Editable(false);
        model.Field(p => p.reading_date).Editable(false);
        model.Field(p => p.error_type).Editable(false);
        model.Field(p => p.station_asset_id).Editable(false);
        model.Field(p => p.ScadaDailyID).Editable(false);
    })
    .Read(read => read.Action("Cleanup_Read", "DataCorrection").Data("sendAntiForgery"))
    .Update(update => update.Action("Cleanup_Update", "DataCorrection").Data("sendAntiForgery"))
    )
)
<script type="text/javascript">
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }
 
    function sendAntiForgery() {
        return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() }
    }
    function refreshGrid(e) {
        if (e.type == 'update')
        {
            e.sender.read();
        }
    }
 
 
</script>
<style>
    .k-grid {
        font-size: 9px;
        width:2000px;
    }
    .k-grid td {
        line-height: 2em;
    }
    .k-readonly {
        color:darkgray;
    }
    .k-grid-header
    {
       font-weight:700;
    }
        .k-grid-header .center-header {
            text-align: center;
        }
    .k-grid-header .wrap-header {
      height: auto;
      overflow: visible;
      white-space: normal;
    }
</style>

 

And my action controller (using Dapper) is shown below (curiously when I check Affected rows shows -1, so not sure why that happens)

[HttpPost]
        [ValidateAntiForgeryToken]
        public IActionResult Cleanup_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<FDMError> errors)
        {
            if (errors != null && ModelState.IsValid)
            {
                var connectionString = _ConnectionString.Value.ConnectionString;
                string subject = Regex.Replace(User.Identity.Name, ".*\\\\(.*)", "$1", RegexOptions.None);
                //subject = "Roberts_C";
                int affectedRows = 0;
                foreach (var correction in errors)
                {
                    //Run your stored procedure here to do a couple of things
                    //insert into the Scada Daily Table
                    //Update the flag on the ScadaErrors table where the ID = to the ID here
                    int scadaErrorID = correction.ID;
                    string stationAssetID = correction.station_asset_id;
                    string stationID = correction.station_id;
                    string errorType = correction.error_type;
                    DateTime readingDate = correction.reading_date;
                    double operatingHours = correction.operating_hrs;
                    double totalDowntimeHours = correction.ttl_downtime_hrs;
                    int horsepowerHours = correction.hrsepwr_hrs;
                    double fuelConsumed = correction.fuel_consumed;
                    int engineStartAttempts = correction.engine_starts_attempts;
                    int engineStartFailed = correction.engine_starts_failed;
                    int engineStartSuccess = correction.engine_starts_success;
                    double startupDuration = correction.startup_duration;
                    double throughputMMCF = correction.thruput_mmcf;
                    int averageUnitRPM = correction.avg_unit_rpm;
                    double oilUsageCompressor = correction.oil_to_comp_cyl;
                    double oilUsageManual = correction.oil_new_cc_hand;
                    //bool errorCorrected = correction.errorCorrected;
                    int blowdownCount = correction.blowdown_cnt;
                    int scadaDailyID = correction.ScadaDailyID;
 
                    DynamicParameters p = new DynamicParameters();
                    p.Add("@ScadaErrorID", correction.ID, dbType: DbType.Int32, direction: ParameterDirection.Input);
                    p.Add("@stationAssetID", correction.station_asset_id, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@stationID", correction.station_id, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@errorType", errorType, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@readingDate", readingDate, dbType: DbType.DateTime, direction: ParameterDirection.Input);
                    p.Add("@operatingHours", operatingHours, dbType: DbType.Double, direction: ParameterDirection.Input);
                    p.Add("@totalDowntimeHours", totalDowntimeHours, dbType: DbType.Double, direction: ParameterDirection.Input);
                    p.Add("@horsepowerHours", horsepowerHours, dbType: DbType.Int32, direction: ParameterDirection.Input);
                    p.Add("@fuelConsumed", fuelConsumed, dbType: DbType.Double, direction: ParameterDirection.Input);
                    p.Add("@engineStartAttempts", engineStartAttempts, dbType: DbType.Int32, direction: ParameterDirection.Input);
                    p.Add("@engineStartFailed", engineStartFailed, dbType: DbType.Int32, direction: ParameterDirection.Input);
                    p.Add("@engineStartSuccess", engineStartSuccess, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@startupDuration", startupDuration, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@throughputMMCF", throughputMMCF, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@averageUnitRPM", averageUnitRPM, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@oilUsageCompressor", oilUsageCompressor, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@oilUsageManual", oilUsageManual, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@blowDownCount", blowdownCount, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@scadaDailyID", scadaDailyID, dbType: DbType.String, direction: ParameterDirection.Input);
                    p.Add("@userID", subject, dbType: DbType.String, direction: ParameterDirection.Input);
 
                    using (var con = new SqlConnection(connectionString))
                    {
 
                        string storedProcName = "scada.usp_UpdateDailyTableByID";
                        con.Open();
                        affectedRows += con.Execute(storedProcName, p, commandType: System.Data.CommandType.StoredProcedure);
                    }
 
                }
            }
 
            return Json(errors.ToDataSourceResult(request, ModelState));
        }
    }
Stefan
Telerik team
 answered on 30 Mar 2018
1 answer
191 views

Is there a way to size the toolbar?  I am using the MVC server side declaration.

 

Thanks

Ivan Danchev
Telerik team
 answered on 30 Mar 2018
1 answer
118 views

HI,

 

The filtering options show for each column, but when "Filter" is clicked nothing changes in the grid.

 

@(Html.Kendo().Grid<FlRazor2.Models.Header>()
                                .Name("grid")
                                .Columns(columns =>
                                {
                                    columns.Bound(p => p.id).Title("Case ID");
                                    columns.Bound(p => p.individual.firstName).ClientTemplate("#=individual? individual.firstName:''#").Title("First Name");
                                    columns.Bound(p => p.individual.lastName).ClientTemplate("#=individual? individual.lastName:''#").Title("Last Name");
                                            //columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
                                        })
                                .ToolBar(tools =>
                                {
                                            //tools.Create();
                                        })
                                .Sortable()
                                .Pageable()
                                //.Filterable()
                                .Filterable(filterable => filterable
                                    .Extra(false)
                                        .Operators(operators => operators
                                        .ForString(str => str.Clear()
                                        .Contains("Contains")
                                        .IsEqualTo("Exactly matches")
                                        .StartsWith("Starts with"))))
                                .DataSource(dataSource =>
                                dataSource
                                .WebApi()
                                .Model(model =>
                                {
                                    model.Id(p => p.id);
                                })
                                .Events(events => events.Error("error_handler"))
                                .Read(read => read.Action("Get", "Home"))
                                //.Create(create => create.Action("Post", "Product"))
                                //.Update(update => update.Action("Put", "Product", new { id = "{0}" }))
                                //.Destroy(destroy => destroy.Action("DELETE", "Product", new { id = "{0}" }))
                                )
                    )

 

from controller:

[HttpGet]
        public DataSourceResult Get([DataSourceRequest]DataSourceRequest request, string t)
        {
            string userName = User.Identity.Name;
            int indexOfSlash = userName.IndexOf("\\");
            userName = userName.Substring(indexOfSlash + 1).ToLower();

            //DataSourceResult test = service.Read().ToDataSourceResult(request);
            //return service.Read().ToDataSourceResult(request);
            IEnumerable<Header> headers = _service.Read();
            DataSourceResult result = new DataSourceResult();
            result.Data = headers;
            result.Total = headers.Count();
            return result;
        }

 

 

Viktor Tachev
Telerik team
 answered on 28 Mar 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?