This is a migrated thread and some comments may be shown as answers.

Kendo Grid MVC Load data based on search

10 Answers 1035 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Medhanie
Top achievements
Rank 1
Veteran
Medhanie asked on 01 Feb 2021, 09:16 PM

Hello;

I want to load data using Kendo MVC Grid based on a requirement.

At first I want to load empty grid, then,

I have an html search textbox where I will provide ID, then

based on the ID provided on the search textbox, I want to load data on the grid.

 

Look at the attached pic for more info.

How can I achieve this, if there is a sample code please give me the link.

 

Looking forward for your help.

Thank you

10 Answers, 1 is accepted

Sort by
0
Medhanie
Top achievements
Rank 1
Veteran
answered on 02 Feb 2021, 11:08 AM
Is there any hope I will get help here?
0
Georgi Denchev
Telerik team
answered on 03 Feb 2021, 02:39 PM

Hi Medhanie,

Thank you for the provided details.

You can set the AutoBind configuration of the grid to false so it won't load the data during initialization.

@(Html.Kendo().Grid<MyModel>()
            .Name("grid")
            .AutoBind(false)
)

I'll assume you have the following input for searching:

<input id="search"/>

You can bind the blur event to it. Blur triggers every time you click outside of the input. In the handling function call the dataSource read method and provide it with the value of the input:

<script>
    $("#search").on("blur", function (e) {
        let value = $(e.currentTarget).val();
        let grid = $("#grid").data("kendoGrid");
        grid.dataSource.read({"inputValue" : value})
    });
</script>

And you can access the value in your controller like this:

public ActionResult Read([DataSourceRequest]DataSourceRequest request, string inputValue)

Let me know if you have any questions.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Medhanie
Top achievements
Rank 1
Veteran
answered on 03 Feb 2021, 07:00 PM

Georgi Denchev

Thank you so much for your help, this just worked without any issue. 

 

I still have problem customizing the style of column textbox in inline edit mode. I want to increase the width/height of the textbox as well as I want to allow either only number/ only alphabets. How can I achieve this?

 

Please look at the attached pic for further clarification. 

0
Georgi Denchev
Telerik team
answered on 04 Feb 2021, 02:40 PM

Hi Medhanie,

You can obtain a reference to the input inside the Edit event of the grid:

.Events(e => e.Edit("onEdit"))
<script>
    function onEdit(e) {
        let propertyNameInput = $(e.container).find("input[id='PropertyName']"); // Get the input associated with the PropertyName field.
        $(propertyNameInput).width(350); // Set the width of the input.
        $(propertyNameInput).prop('type', 'number'); // Change the type of the input to a number.
    }
</script>

You can modify multiple inputs at once, it doesn't have to be just one.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Medhanie
Top achievements
Rank 1
Veteran
answered on 04 Feb 2021, 10:15 PM

thank you for replying;

I am able to increase the height and width of the input text but unable to write multiple line, how can I change the input type to textarea so that the user can type multiple line?

 

thank you

0
Georgi Denchev
Telerik team
answered on 05 Feb 2021, 02:50 PM

Hello Medhanie,

I'd recommend the same approach as I mentioned in the other ticket.

Create an Editor Template just for one of the properties. Define a TextArea widget in this template and assign it to the property that you want to use an area.

In the Views/Shared/EditorTemplates folder create a new View TextAreaEditor.cshtml and add the widget inside of it:

@model string
@(Html.Kendo().TextAreaFor(m => m)
    .Rows(5)
)

After that use the UIHint attribute to set the template to a property in your model:

[UIHint("TextAreaEditor")]
public string MyProperty { get; set; }

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Medhanie
Top achievements
Rank 1
Veteran
answered on 05 Feb 2021, 03:40 PM

Hi Georgi;

Is the implementation going to be different for InLine mode of editing? Am not able to get there, sorry

0
Georgi Denchev
Telerik team
answered on 05 Feb 2021, 04:02 PM

Hello Medhanie,

The implementation for both Inline and Popup modes would be the same.

Let me know if you face any issues.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Medhanie
Top achievements
Rank 1
Veteran
answered on 05 Feb 2021, 04:18 PM

In that case, I have some issue, binding the existing data to be edited, I explained this in the other ticket

0
Georgi Denchev
Telerik team
answered on 05 Feb 2021, 04:29 PM

Hello Medhanie,

Let's continue the discussion in the ticket, I'll provide my response there.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Medhanie
Top achievements
Rank 1
Veteran
Answers by
Medhanie
Top achievements
Rank 1
Veteran
Georgi Denchev
Telerik team
Share this question
or