Telerik Forums
UI for ASP.NET MVC Forum
0 answers
9 views

Hello, 

I can't get the Destroy method to work, I often get a 415 error with the GetListUsersDto object as parameters. 

@(Html.Kendo().Grid<GetListUsersDto>().Name("GetListUsersGrid")
        .Groupable()
        .Sortable()
        .Editable()
        .Scrollable()
        .ToolBar(x => x.Create())
        .Columns(columns =>
        {
            columns.Bound(c => c.ID).Title(@Localizer["Tab_User_Id"].Value);
            columns.Bound(c => c.Surname).Title(@Localizer["Editing_User_Surname"].Value);
            columns.Bound(c => c.Firstname).Title(@Localizer["Editing_User_Firstname"].Value);
            columns.Bound(c => c.RoleName).Title(@Localizer["Editing_User_Role"].Value);
            columns.Bound(c => c.DateDebActif).Title(@Localizer["Editing_User_Start_Date"].Value).Format("{0:M/d/yyyy HH:mm:ss}"); ;
            columns.Bound(c => c.DateFinActif).Title(@Localizer["Editing_User_End_Date"].Value).Format("{0:M/d/yyyy HH:mm:ss}"); ;
            columns.Command(c =>
            {
                c.Edit();
                c.Destroy();
            });
        }).DataSource(dataSource => dataSource.Ajax()
        .Read(r => r.Action("getusers", "admin"))
        .Create(r => r.Action("createuser", "admin"))
        .Destroy(r => r.Action("deleteuser", "admin"))
            .Model(model =>
            {
        model.Id(m => m.ID);
        model.Field(f => f.ID).DefaultValue(Guid.NewGuid());
    }
    )).Pageable())
    [HttpPost]
    [Authorize(PolicyEnum.Administrateur)]
    [Route("deleteuser")]
    public string DeleteUser([DataSourceRequest] DataSourceRequest request, GetListUsersDto dto)
    {
        //var result = adminService.DeleteUser(dto.ID);
        return JsonConvert.SerializeObject(new {/* error = result.IsError, message = localizer[result.IdMessage].Value + result.Message */});
    }
public class GetListUsersDto
{
    public Guid ID { get; set; }
    public string Surname { get; set; }
    public string Firstname { get; set; }
    public string Username { get; set; }
    public bool IsActif { get; set; }
    public int RoleId { get; set; }
    public string RoleName { get; set; }
    public int LangId { get; set; }
    public string LangName { get; set; }
    public DateTime DateDebActif { get; set; }
    public DateTime DateFinActif { get; set; }
}

If I change my GetListUsersDto method to Guid ID, the method works but the Guid is empty.

 [HttpPost]
 [Authorize(PolicyEnum.Administrateur)]
 [Route("deleteuser")]
 public string DeleteUser([DataSourceRequest] DataSourceRequest request, Guid Id)
 {
     //var result = adminService.DeleteUser(Guid.Parse(ID));
     return JsonConvert.SerializeObject(new {/* error = result.IsError, message = localizer[result.IdMessage].Value + result.Message */});
 }

If I only set a DataSourceRequest request, the method works, but doesn't return a usable object for my service.

    [HttpPost]
    [Authorize(PolicyEnum.Administrateur)]
    [Route("deleteuser")]
    public string DeleteUser([DataSourceRequest] DataSourceRequest request)
    {
        //var result = adminService.DeleteUser();
        return JsonConvert.SerializeObject(new {/* error = result.IsError, message = localizer[result.IdMessage].Value + result.Message */});
    }

I don't know what to do. Does anyone have a solution or idea?

Thank you,

Stéphane
Top achievements
Rank 1
 asked on 18 Apr 2024
0 answers
17 views

Hi all,

I have a grid with multiple cascading dropdown columns, each dropdown gets filtered calling a method in my controller.

What I want now it is simply populate a non editable text column based on the value from one of my previous dropdowns calling a filter method on my controller.

Thank you

LnZ

 

Lorenzo
Top achievements
Rank 1
 asked on 16 Apr 2024
0 answers
18 views

Hi,

I am getting extra characters like Ã¾Ã¿PDF Check in metadata of the exported PDF from Kendo grid. That reflects into the title of the PDF in chrome browser.

Is there any way to remove that extra characters from the metadata using jQuery?

I am attaching screenshot of the PDF file.

 

Trusha
Top achievements
Rank 1
Iron
 asked on 01 Apr 2024
0 answers
25 views

Hello,

I'm encountering an issue with the autocomplete functionality in Kendo UI Grid. While the data selected through autocomplete is correctly added to hidden fields, it does not appear in the Grid.

Specifically, after using the autocomplete functionality, I checked whether the correct data was added to the respective hidden fields and found that the values I expected were indeed present in those fields. However, I noticed that these values were not visible in the Grid. This implies that the data selected by users is not being properly reflected within the Grid.

In summary, I am unable to display the data received through the autocomplete functionality within the Grid. I would appreciate any suggestions to resolve this issue.

The code structure related to the problem I mentioned above is as follows.

@(Html.Kendo().Grid(Model.Lines)
    .Name("OrderLines")
    .ToolBar(tools => tools.Create().Text("Add new product"))
    .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
    .Events(events => events
    .Change("onChange"))
    .Columns(columns =>
    {
        columns.Bound(p => p.Title)
        .ClientTemplate("#= Title #" +
        "<input type='hidden' name='Lines[#= index(data)#].Title' value='#= Title #' />")
        .EditorTemplateName("ProductTitleAutoComplete");

        columns.Bound(p => p.Title).Hidden().ClientTemplate("#= Title #" +
        "<input type='hidden' name='Lines[#= index(data)#].Title' value='#= Title #' />"
        );

        columns.Bound(p => p.Description).ClientTemplate("#= Description #" +
        "<input type='hidden' name='Lines[#= index(data)#].Description' value='#= Description #' />"
        );

        columns.Bound(p => p.Quantity).ClientTemplate("#= Quantity #" +
        "<input type='hidden' name='Lines[#= index(data)#].Quantity' value='#= Quantity #' />"
        );

        columns.Bound(p => p.UnitPrice).ClientTemplate("#= UnitPrice #" +
        "<input type='hidden' name='Lines[#= index(data)#].UnitPrice' value='#= UnitPrice #' />"
        );

        columns.Bound(p => p.TaxRate).ClientTemplate("#= TaxRate #" +
        "<input type='hidden' name='Lines[#= index(data)#].TaxRate' value='#= TaxRate #' />"
        );

        columns.Bound(p => p.DiscountRate).ClientTemplate("#= DiscountRate #" +
        "<input type='hidden' name='Lines[#= index(data)#].DiscountRate' value='#= DiscountRate #' />"
        );

        columns.Bound(p => p.PurchaseOrderId).Hidden().ClientTemplate("#= PurchaseOrderId #" +
        "<input type='hidden' name='Lines[#= index(data)#].PurchaseOrderId' value='#= PurchaseOrderId #' />"
        );

        columns.Bound(p => p.ProductId).Hidden().ClientTemplate("#= ProductId #" +
        "<input type='hidden' name='Lines[#= index(data)#].ProductId' value='#= ProductId #' />"
        );

        columns.Bound(p => p.Id).Hidden().ClientTemplate("#= Id #" +
        "<input type='hidden' name='Lines[#= index(data)#].Id' value='#= Id #' />"
        );

        columns.Bound(p => p.MeasureWeightId).ClientTemplate("#= MeasureWeightId #" +
        "<input type='hidden' name='Lines[#= index(data)#].MeasureWeightId' value='#= MeasureWeightId #' />"
        );

        columns.Command(command => command.Destroy()).Width(100);
    })
    .DataSource(dataSource => dataSource.Ajax()
    .Model(model =>
    {
        model.Id(p => p.ProductId);
        model.Field(p => p.ProductId).Editable(false);
    })
    .ServerOperation(false)
    ))

function onChange_ProductAutoComplete(e) {
    var dataItem = e.sender.dataItem(0);

    var grid = $("#OrderLines").data("kendoGrid");

    if (dataItem) {
        var el = $(e.sender.element[0]);
        const parent = el.closest("td");
        const inputs = parent.siblings().find('input');

        $(inputs).each(function () {
            var name = $(this).attr('name');
            if (name.endsWith("Description")) {
                $(this).val(dataItem.Notes);
            } else if (name.endsWith("ProductId")) {
                $(this).val(dataItem.Id);
            }
            else if (name.endsWith("Title")) {
                $(this).attr({ value: dataItem.Title });
                $(this).val(dataItem.Title);
            }
            else if (name.endsWith("MeasureWeightId")) {
                $(this).val(dataItem.MeasureWeightId);
            }
        });
    }
}

function onReadDataOnGrid_ProductAutoComplete(e) {
    let data = {
        title: $('#Title_ProductAutoComplete').val()
    };

    return data;
}

Thank you in advance for your support.

Selman
Top achievements
Rank 1
 asked on 18 Mar 2024
0 answers
22 views

I had a request to change the filtering of a certain column from "Starts With" to use a multi-select checkbox type filter to facilitate selecting 5-10 random items.  Then of course some other users prefer the "Starts With" type of filtering.  My solution is to have dual columns for that particular field, one with each filter type.  

Since my grids save user preferences in local storage between sessions, the users can hide whichever column has the filtering they don't prefer and just use the other one.  When they reload the page, their choice of column persists and their filtering is how they like it.

Darron

 

 

Darron
Top achievements
Rank 1
 asked on 18 Mar 2024
0 answers
19 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
0 answers
32 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.

0 answers
31 views

Hi Team,

 

I am facing issue in ClientDetailTemplateId Grid when using checkbox, data coming from database is true checkbox selected but if we checkbox checked or uncheck then checkbox values not sending proper values in jquery bellow sending code for grid.

  @(
      Html.Kendo().Grid<PNWorklistSupplierGridViewModel>()
                          .Name("pnwlGrid_#=Id#") // template expression, to be evaluated in the master context
                              .Columns(columns =>
                               {
                                   columns.Command(command =>
                                    {
                                        command.Custom("editPn1").Text(" ").IconClass("k-icon k-i-pencil").Click("OpenSupplierEditWindowPN");
                                    }).Width(40).HtmlAttributes(new { @style = "text-align: center;" });

                                        columns.Bound(e => e.Check).Title("test").Width(150)
                                   .ClientTemplate("<input type='checkbox' \\#=Check? checked='checked' : '' \\# />")
                                   .HeaderHtmlAttributes(new { @class = "headerText" }).Sortable(false).Filterable(false).HtmlAttributes(new { @style = "text-align: center;" }); 

If Check checkbox checked then js file getting Check values false

please check and let me know any thing else required.

 

Thank you!

Ramesh
Top achievements
Rank 1
 asked on 07 Feb 2024
0 answers
34 views

Hi, im currently creating a Grid with dynamic columns and came across with this post and current following the structure.

Dynamic Data in the Kendo UI Grid (telerik.com)

 

My problem is that during Update, I cant seem to access the Property Values of those edited columns. 

Can I get the actual code for the "Update" of this demo API?

https://demos.telerik.com/kendo-ui/service/products/Update

 

Heres my update code btw:

            

[HttpPost]
        public JsonResult Update_Employee([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<dynamic> models)
        {
            foreach(var obj in models)
            {
                string a = GetProperty(obj, "EmployeeName");

            }

            return Json(ModelState.ToDataSourceResult());
        }

        private object GetProperty(dynamic obj, string propertyName)
        {
            var objDict = obj as IDictionary<string, object>;
            if (objDict.ContainsKey(propertyName))
            {
                var value = objDict[propertyName];

                if (value != null)
                    return value;
            }

            return null;
        }

 

 

 

 

 

 

DPA
Top achievements
Rank 1
 asked on 29 Jan 2024
0 answers
43 views

Hi, I have this list of thousands of employees from our Database and will be displayed in a Grid via ViewModel. Im using Custom Binding with paging to fetch only specific number of records per page to reduce the loading time of the grid thats why the ServerOperation = true.

My problem is that, how can I customize or recreate the request filters? Since FullName and Address does not exists in the Employees table. I'm getting error whenever i use search.

 

public class Employee
    {
        public string EmployeeID { get; set; }

        public string LastName { get; set; }
        public string FirstName { get; set; }

        public string Street { get; set; }
        public string City { get; set; }
        public string Province { get; set; }

        public string TelephoneNo { get; set; }

        public string FullName
        {
            get
            {
                return String.Format("{0}, {1}", LastName, FirstName ?? "");
            }
        }

        public string Address
        {
            get
            {
                return String.Format("{0} {1} {2}", Street, City, Province);
            }
        }
    }

@(Html.Kendo().Grid<Employee>()
    .Name("gridEmployees")
    .ToolBar(toolbar =>
    {
        toolbar.Search();
    })
    .Columns(column =>
    {
        column.Bound(c => c.EmployeeID);
        column.Bound(c => c.FullName);
        column.Bound(c => c.Address);
        column.Bound(c => c.TelephoneNo);
    })
    .Filterable()
    .AutoBind(false)
    .DataSource(ds =>
    {
        ds.Ajax()
        .ServerOperation(true)
        .PageSize(10)
        .Model(m => m.Id(c => c.EmployeeID))
        .Read(r => r.Action("Read", "Employees"));
    })
)

        
DPA
Top achievements
Rank 1
 asked on 19 Jan 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?