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

Validation on Databound Event of Grid

2 Answers 669 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 05 Sep 2018, 06:42 PM

My application consists of a couple of pages of data populating a grid.  This data is made up of dirty data that needs to be cleaned up.  The user wants to see if we can populate the data and when the page renders, show the cells with bad data in them -- basically run the validation code for every cell of every row in the grid. .  My guess is that this would be cpu intensive and would need to occur on the databound event of the grid.  Is this even possible? 

 

Error Type Col1     Col2     Col3   Col4    Col5

Out of Range

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 06 Sep 2018, 12:28 PM
Hi Michael,

You are correct, you can achieve this requirement using the dataBound event handler:
.Events(e => e.DataBound("gridDataBound"))
JavaScript:
<script>
    function gridDataBound(args) {
        var grid = this;
        var items = grid.items();
 
        for (var i = 0; i < items.length; i++) {
            var item = $(items[i]);
            var dataItem = grid.dataItem(item);
            if (dataItem.ID == "5" || dataItem.ProductName.indexOf("5") >= 0) {
                item.find("td")[0].style.backgroundColor = "lime";
            }
        }
    }
</script>

Alternatively, you can use a template to achieve this requirement:
https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-apply-conditional-logic-to-client-column-templates

Similar to this:
https://dojo.telerik.com/@bubblemaster/EjoBAn

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Michael
Top achievements
Rank 1
answered on 06 Sep 2018, 05:40 PM
Thanks for the reply.  What's funny is I didn't even realize I had posted this.  I could have sworn my browser died and I never got a chance to go back to repost.  I think I am going to push back on this as this will require me to convert all my server side validation code to javascript validation code.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Michael
Top achievements
Rank 1
Share this question
or