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

Error handling grid filter

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Graeme
Top achievements
Rank 1
Graeme asked on 03 Nov 2015, 12:20 PM

I have a radgrid set up to allow filtering on date columns which appears to be working fine.

However I can't work out how to deal with invalid input. For example  entering text instead of a date crashes the page.

Can anyone point me in the right direction of how I can either trap the error (eg where to put a try/catch block) and/or how I can apply an input mask?

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 06 Nov 2015, 08:59 AM
Hi,

You can access the picker filter control and on its OnError client event fire a custom message for example:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem filterItem = e.Item as GridFilteringItem;
        foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)
        {
            if (column is GridDateTimeColumn && (column as GridDateTimeColumn).AllowFiltering)
            {
                RadDatePicker picker = filterItem[column.UniqueName].Controls[0] as RadDatePicker;
                picker.DateInput.ClientEvents.OnError = "customError";
            }
        }
    }
}

JS:
<script>
            function customError() {
                alert("The date should be in the following format: MM/dd/yyyy");
            }
        </script>


Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Graeme
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or