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

I have a RadGrid that's losing the ability to sort columns by clicking the column header. I've narrowed it down to some code in my ItemDataBound method that updates the header text. If I remove this code, clicking the column headers works properly. But when I put it back, sorting is disabled. 

Here's my grid:

<telerik:RadGrid ID="RadGrid1" runat="server"
    AllowSorting = "true"
 
    OnNeedDataSource="RadGrid1_NeedDataSource"
    OnItemDataBound="RadGrid1_ItemDataBound"
    OnPreRender="RadGrid1_PreRender"
     
    RenderMode="Classic"
    Skin="Windows7">
</telerik:RadGrid>

 

Here's my ItemDataBound method:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) {
    if (e.Item is GridHeaderItem) {
        GridHeaderItem header = (GridHeaderItem)e.Item;
        header["MONTH_NAME_LONG"].Text = "Month";
    }
}

 

Any idea why this is happening?

bdrennen
Top achievements
Rank 1
 answered on 23 Jan 2019
4 answers
1.2K+ views

Hello,

I have an application that has many different tables that need to be presented to the user - some of these have over 200k rows of data.

We currently use a very bad and basic search feature, along with .skip(x), .take(x) to only get a certain amount of data per page.

What I do above works, but lacks more advanced filtering.

I'm currently evaluating and looking at grid, but, I am very confused - it supports paging and by increasing the sample app to return 200k items, I can see through network monitoring that it only pulls the single page at a time, however, I'm getting lost trying to evaluate this product...

... The docs don't seem to go in to that much details and the demos page seems to be better, but neither give any information about performance tuning, limiting the result set and similar - I'm worried that if I link this to the live data, I'm going to introduce a lot of problems.

Are there any other documentation bits that I am missing?

Georgi
Telerik team
 answered on 23 Jan 2019
3 answers
838 views

1.when i change the Brower width, the text auto wrap and the row height grow. I want to set the text not wrap(see attachment), how can I do that.

2.I want to set text wrap in edit mode, how can I do that?

 

Viktor Tachev
Telerik team
 answered on 22 Jan 2019
3 answers
930 views

I am attempting to call a function in the controller when the Destroy button is clicked on a row. The controller will then delete the record in the database. I also need to pass in the ID of the employee to identify which record in the database to delete. Thank you!

This is what I have:

@(Html.Kendo().Grid<TelerikAspNetCoreApp1.Models.EmployeeViewModel>()
    .Name("grid")
    .ToolBar(toolbar => toolbar.Create().Text("ADD").HtmlAttributes(new { title = "Add Employee" }))
    .Columns(columns =>
    {
        columns.Bound(p => p.EmployeeName);
        columns.Bound(p => p.Active);
        columns.Command(command =>
        {
            command.Destroy().HtmlAttributes(new { title = "Delete Highlighted Employee" });
        }).Width(150);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:450px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Employee_Read", "Grid"))
        .Destroy(update => update.Action("Employee_Delete", "Grid"))
    )
)
Mark
Top achievements
Rank 1
 answered on 21 Jan 2019
2 answers
133 views

.Net Core 2.1,the cshtml

@using Kendo.Mvc.UI
@(Html.Kendo().Grid<Liwb.Entities.Travel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ID);
        columns.Bound(p => p.Name);
        columns.Bound(p => p.Pos);
        columns.Bound(p => p.IsDelete);
        columns.Bound(p => p.From);
        columns.Bound(p => p.To);
        columns.Bound(p => p.StartDate).Format("{0:MM/dd/yyyy}");
        columns.Bound(p => p.EndDate).Format("{0:MM/dd/yyyy}");
        columns.Bound(p => p.IntervalDays);
        columns.Bound(p => p.TrafficType);
        columns.Bound(p => p.PhotographDirectory);
        columns.Bound(p => p.ProblemDocument);
        columns.Command(commands =>
        {
            commands.Edit();
            commands.Destroy(); // The "destroy" command removes data items.
        }).Title("Commands").Width(200);
    })
    .Editable(editMode => editMode.Mode(GridEditMode.InLine))
    .Pageable()
    //.Sortable()
    .Scrollable()
    //.Filterable()
    .HtmlAttributes(new { style = "height:100%; width:100%" })
    .DataSource(dataSource => dataSource
        .WebApi()
        .Model(Model => { Model.Id(p => p.ID);})
        .Events(events=>events.Error("error_handler"))
        .Read(read => read.Action("Get", "Travel"))
        .Create(create => create.Action("Post", "Travel"))
        .Update(update => update.Action("Put", "Travel", new { id = "{0}" }))
        .Destroy(destory => destory.Action("Delete", "Travel", new { id = "{0}" }))
    )
)

the api controller
namespace PlantManagement.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TravelController : ControllerBase
    {
        private readonly PlantManagementDbContext _context;
        public TravelController(PlantManagementDbContext context)
        {
            _context = context;
        }
        //MVC return Value: ActionResult
        // GET: api/Travel
        [HttpGet]
        //public IEnumerable<Travel> GetTravels()
        public DataSourceResult Get([DataSourceRequest]DataSourceRequest request)
        {
            return _context.Travels.ToDataSourceResult(request);//.Where(p => p.PID == null)
        }
        // GET: api/Travel/5
        [HttpGet("{id}")]
        public async Task<IActionResult> Get([FromRoute] long id)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var travel = await _context.Travels.FindAsync(id);
            if (travel == null)
            {
                return NotFound();
            }
            return Ok(travel);
        }
        // PUT: api/Travel/5
        [HttpPut("{id}")]
        public async Task<IActionResult> Put([FromRoute] long id, [FromBody] Travel travel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if (id != travel.ID)
            {
                return BadRequest();
            }
            _context.Entry(travel).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TravelExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }
            return NoContent();
        }
        // POST: api/Travel
        [HttpPost]
        public async Task<IActionResult> Post( Travel travel)//[FromBody]
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            _context.Travels.Add(travel);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TravelExists(travel.ID))
                {
                    return new StatusCodeResult(StatusCodes.Status409Conflict);
                }
                else
                {
                    throw;
                }
            }
            return CreatedAtAction("GetTravel", new { id = travel.ID }, travel);
        }
        // DELETE: api/Travel/5
        [HttpDelete("{id}")]
        public async Task<IActionResult> Delete([FromRoute] long id)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var travel = await _context.Travels.FindAsync(id);
            if (travel == null)
            {
                return NotFound();
            }
            travel.IsDelete = true;
            //_context.Travels.Remove(travel);
            await _context.SaveChangesAsync();
            return Ok(travel);
        }
        private bool TravelExists(long id)
        {
            return _context.Travels.Any(e => e.ID == id);
        }
    }
}

Tsvetomir
Telerik team
 answered on 21 Jan 2019
1 answer
1.7K+ views

Hi there,

I am using a simple Kendo grid which contains a pop up form to allow a user to either add or delete new "categories" (many) for one product.

popup

@using KendoGridOneToMany.Models
 
@(Html.Kendo().Grid<ProductModel>()
                        .Name("persons")
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .Model(model => model.Id(m => m.Id))
                            .Read(read => read.Action("GetProducts", "Home"))
                            .Update(up => up.Action("UpdateCategory", "Home"))
                            .Create(x => x.Action("CreateProduct", "Home"))
                    )
                    .ToolBar(x => x.Create())
                    .Columns(columns =>
                    {
                        columns.Bound(c => c.Id).Width(200);
                        columns.Bound(c => c.Type);
                        columns.Bound(c => c.DisplayCatogories);
                        columns.Command(cmd => cmd.Edit());
                    })
                    .Events(ev => ev.Edit("addDeleteButton"))
                    .Pageable()
                    .Sortable()
            .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("PopUpView"))
)

I have altered the pop up to contain an additional "delete" button. As this extra button is not supported by the grid's inbuilt update function, I have used AJAX to capture data within the pop up held in a form and return it to the controller's separate "delete" method.

The pop up form code is contained on a partial view that looks like so:

@model ProductModel
<div>
<fieldset id="popUpForm">
    <dl>
        <dt>
            @Html.HiddenFor(m => m.Id)
            @Html.ValidationMessageFor(m => m.CategoryId)
 
        </dt>
        <dd>
            @(Html.Kendo().DropDownListFor(m => m.CategoryId).AutoBind(false).OptionLabel("Select Category...").DataTextField("Name").DataValueField("Id").DataSource(dataSource =>
                                                  { dataSource.Read(read => read.Action("GetCategories", "Home")).ServerFiltering(true); }))
        </dd>
    </dl>
</fieldset>

And just for reference, the "Product" model like so:

public ProductModel()
{
   public int Id { get; set; }
 
   public string Type { get; set; }
 
   public int CategoryId { get; set; }
 
   public ICollection<CategoryModel> Categories { get; set; }
 }

I've added the delete button by using the grid's edit event to add the button dynamically via JavaScript:

function addDeleteButton(e) {
    $('<a class="k-button k-button-icontext k-grid-delete custom"
    href="\\#"k-icon k-i-delete"></span>Delete</a>').insertAfter(".k-grid 
     -update");
    $('.k-window-title').text("Edit Categories");
    $(".custom").click(function (e) {
        e.preventDefault();
        var formContainer = $("#popUpForm");
        SubmitInfo(formContainer);
    });
}

 

So, when the user selects a category, they have the option to either add or delete a category from the selected "product". However, where "add" is handled by Kendo, I need to handle delete using AJAX.

The delete button is linked to the following JavaScript.

function SubmitInfo(formContainer) {
    var grid = $("#persons").data("kendoGrid"),
        parameterMap = grid.dataSource.transport.parameterMap;
    var data = parameterMap({ sort: grid.dataSource.sort(), filter: grid.dataSource.filter(), group: grid.dataSource.group() });
    $.ajax({
        url: '@Url.Action("Delete", "Home")',
        type: "POST",
        dataType: "JSON",
        data: data + "&" + formContainer.serialize(),
        success: function (result) {
               // Clear the input tags
                formContainer.find("input[type='text']").each(function (i, element) {
                    $(this).val('');
                });
                $('#persons').data('kendoGrid').dataSource.read();
                $('#persons').data('kendoGrid').refresh();
            }
        }
    });
}

 

And the corresponding Controller method like this:

[HttpPost]
   public Void Delete([DataSourceRequest] DataSourceRequest request, ProductModel product)
    {
        var productModel = siteRepository.GetProductById(product.Id);
        var categoryToRemove = productModel.Categories.SingleOrDefault(r => r.Id == product.CategoryId);
        if (categoryToRemove != null)
        {
            product.Categories.Remove(categoryToRemove);
            siteRepository.UpdateProduct(product);
        }
    }

 

This works pretty well at posting back the required Id from the desired Category, but I am unable to persist the Product ID back to the controller required to know from which product to remove the selected category from. This is despite including the relevant @Html.HiddenFor(m => m.Id) in the pop up form.

Error

Would anyone know the best way to persist that piece of data from my pop up form to my controller?

 

Tsvetomir
Telerik team
 answered on 18 Jan 2019
2 answers
111 views
How is that handled?  Binding to a column that is a nullable date time?
Reid
Top achievements
Rank 2
 answered on 18 Jan 2019
1 answer
118 views

Hello. I have a problem with grid edit in line.

 

I have defined normal grid, which uses ViewModel.

ViewModel has 3 fields (int A, int B, bool checkbox) 

A field isn't editable by default but whenever I click "edit" I can change B field or check/uncheck checkbox.

I'd like to make field A make editable whenever checkbox is checked by user during edition. So after the checkbox is check A fields is editable.

 

Greetings

Tsvetomir
Telerik team
 answered on 18 Jan 2019
0 answers
58 views

I have two charts, and I'd like to make it so the second chart updates when the series in the first chart is clicked. There's a master page with my RadAjaxManager, so I'm using a RadAjaxManagerProxy with these two charts. I'm having trouble converting the code samples I see in the documentation to work with my RadAjaxManagerProxy.

Here are my two charts:

<telerik:RadHtmlChart ID="Chart_Referrals_By_Month" runat="server" DataSourceID="ReferralsByMonth" Skin="Windows7" RenderMode="Lightweight" Height="250">
     <ClientEvents OnSeriesClick="OnSeriesClick"/>
     <PlotArea>
         <Series>
             <telerik:LineSeries Name="Column1" DataFieldY="AVERAGE_REFERRALS">
                 <TooltipsAppearance Visible="false"></TooltipsAppearance>
                 <Appearance>
                     <FillStyle BackgroundColor="#add8e6"></FillStyle>
                 </Appearance>
             </telerik:LineSeries>
         </Series>
         <XAxis DataLabelsField="MONTH_NAME" Color="black" MajorTickSize="0" MinorTickSize="2" MinorTickType="Outside">
             <LabelsAppearance RotationAngle="-45" />
             <MajorGridLines Visible="false" />
             <MinorGridLines Visible="true" />
         </XAxis>
         <YAxis AxisCrossingValue="0" Color="black" MajorTickSize="2" Step="1">
             <LabelsAppearance DataFormatString="{0}" RotationAngle="0" Skip="0" />
             <TitleAppearance Position="Center" RotationAngle="0" Text="Percent" Visible="false" />
             <MajorGridLines Visible="false" />
             <MinorGridLines Visible="false" />
         </YAxis>
     </PlotArea>
     <ChartTitle Text="Referrals per Day by Month - Average"></ChartTitle>
     <Legend>
         <Appearance BackgroundColor="Transparent" Position="Bottom" Visible="false"></Appearance>
     </Legend>
 </telerik:RadHtmlChart>

 

<telerik:RadHtmlChart ID="Chart_Referrals_By_Day" runat="server" DataSourceID="ReferralsByDay" Skin="Windows7" RenderMode="Lightweight" Height="250">
    <PlotArea>
        <Series>
            <telerik:LineSeries Name="Column1" DataFieldY="PERCENT_REFERRALS">
                <TooltipsAppearance Visible="false"></TooltipsAppearance>
                <Appearance>
                    <FillStyle BackgroundColor="#add8e6"></FillStyle>
                </Appearance>
            </telerik:LineSeries>
        </Series>
        <XAxis DataLabelsField="DAY_NAME_LONG" Color="black" MajorTickSize="0" MinorTickSize="2" MinorTickType="Outside">
            <LabelsAppearance RotationAngle="-45" />
            <MajorGridLines Visible="false" />
            <MinorGridLines Visible="true" />
        </XAxis>
        <YAxis AxisCrossingValue="0" Color="black" MajorTickSize="2">
            <LabelsAppearance DataFormatString="{0}" RotationAngle="0" Skip="0" />
            <TitleAppearance Position="Center" RotationAngle="0" Text="Percent" Visible="false" />
            <MajorGridLines Visible="false" />
            <MinorGridLines Visible="false" />
        </YAxis>
    </PlotArea>
    <ChartTitle Text="Referrals by Day - %"></ChartTitle>
    <Legend>
        <Appearance BackgroundColor="Transparent" Position="Bottom" Visible="false"></Appearance>
    </Legend>
</telerik:RadHtmlChart>

Here's my JavaScript:

function OnSeriesClick(args) {
    var kendoWidget = args.sender;
    if (args.value > 0) {
        $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest(args.category);
    }
} // end OnSeriesClick

 

What I don't know is how to handle this on the server side. From the Implementing Drill-Down Functionality example, I have:

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) {
    string seriesName = Chart_Referrals_By_Month.PlotArea.Series[0].Name;
} // end RadAjaxManager1_AjaxRequest

 

However, this line never executes. I'm missing a step here, and I was hoping you could point out what I need.

Thank you!

bdrennen
Top achievements
Rank 1
 asked on 17 Jan 2019
2 answers
282 views

We are experiencing an issue with the virtual scrolling of a combobox when used as a custom editor template in a grid with in-cell editing. I have a solution to demonstrate the issue, but it is too large to upload.

Basically, when clicking into the combobox, the control is bound and looking at the web requests, the value is passed correctly to the ValueMapper and the index is retrieved correctly from the server. However, if you then TAB or press ENTER in the combobox, it attempts to retrieve the value based on the text in the combobox, clearing the reference.

Veselin Tsvetanov
Telerik team
 answered on 17 Jan 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?