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

deselect when grid loses focus

3 Answers 248 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 2
Elliott asked on 04 Jan 2012, 05:24 PM
I am replacing 2 grids from another third-party (Intersoft) on a page and am trying to not change any of the functionality
there is a property set which deselects any item from either grid when that grid loses focus
I tried Grid1.Attributes.Add("onblur", function_name()); but no dice

in IE, that is
I do my development in IE then post and test in the other browsers
blur works in Mozilla but not sure about the parameters - but I could just use 2 functions

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 05 Jan 2012, 10:53 AM
Hello Marianne,

I tested this approach and it works on my side as long as the grid has been focused before I click outside of it - note that selecting a row in RadGrid does not focus the grid.

Here is the grid I used:
<script type="text/javascript">
    function deselectGrid() {
        $find('<%=RadGrid1.ClientID %>').clearSelectedItems();
    }
</script>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="false" GridLines="None"
    Skin="Vista" OnNeedDataSource="gridParameters_NeedDataSource" AutoGenerateColumns="true"
    AllowMultiRowSelection="true">
    <MasterTableView EditMode="EditForms" DataKeyNames="A">
        <Columns>
            <telerik:GridClientSelectColumn>
            </telerik:GridClientSelectColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true">
    </ClientSettings>
</telerik:RadGrid>


protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    RadGrid1.Attributes.Add("onblur", "deselectGrid();");
 
}
 
protected void gridParameters_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    ArrayList list = new ArrayList();
    list.Add(new TestListItem("Item 0", 0));
    list.Add(new TestListItem("Item 1", 2));
    list.Add(new TestListItem("Item 2", 1));
 
    RadGrid1.DataSource = list;
}
public class TestListItem
{
    private string _a;
    private int? _b;
    public TestListItem(string a, int? b)
    {
        this._a = a;
        this._b = b;
    }
    public string A
    {
        get
        {
            return this._a;
        }
        set
        {
            this._a = value;
        }
    }
    public int? B
    {
        get
        {
            return this._b;
        }
    }
}

If you want to make sure the grid is focused during selection, you could at some certain client events (like OnRowSelected) focus its element:
gridInstance.get_element().focus();


All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Elliott
Top achievements
Rank 2
answered on 05 Jan 2012, 03:04 PM
I added the statement to focus the grid on both row selected functions - still didn't work in IE
it's not critical functionality so I'll live with it only deselecting in Mozilla and Chrome
0
Elliott
Top achievements
Rank 2
answered on 09 Jan 2012, 09:53 PM
update - IE doesn't trigger an onblur event for a span element
use onfocusout instead
in the page load, not a postback:

HttpBrowserCapabilities Lugs = Request.Browser;
if (Lugs.Type.StartsWith("IE"))
{
    rgItems.Attributes.Add("onfocusout", "rgItems_OnBlur()");
    rgOrder.Attributes.Add("onfocusout", "rgOrder_OnBlur()");
}
else
{
    rgItems.Attributes.Add("onblur", "rgItems_OnBlur()");
    rgOrder.Attributes.Add("onblur", "rgOrder_OnBlur()");
}
Tags
Grid
Asked by
Elliott
Top achievements
Rank 2
Answers by
Tsvetina
Telerik team
Elliott
Top achievements
Rank 2
Share this question
or