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

Focus at end of grid filter.

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt
Top achievements
Rank 1
Kurt asked on 30 Jul 2014, 11:23 AM
Hi everyone,

I've got Grid with filter columns and everything works fine except focus.
I lost focus after FilterDelay elapsed. I tried to set focus with
ItemCommand and PreRender but cursor appears at the beginning of
textbox, not at the end, like this demo. (Client side binding)

How can I fix that? Is it possible?

Regards,

Kurt

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 30 Jul 2014, 03:31 PM
Hello Kurt,

The demo that you are referring to is using client-side binding and no postback occurs, so the focus is not lost in the first place.

For your scenario, the easiest approach that I could suggest is that you wrap your RadGrid in a RadAjaxPanel for example (or use RadAjaxManager) and handle the client-side OnRequestStart and OnResponseEnd events, where you could save the focused control before the request and set it back after the request ends.

Following is simple example demonstrating that approach:
<telerik:RadCodeBlock ID="codeBlock1" runat="server">
    <script type="text/javascript">
        var requestInitiator = null;
        var selectionStart = null;
 
        function requestStart(sender, args) {
            requestInitiator = document.activeElement.id;
            if (document.activeElement.tagName == "INPUT") {
                selectionStart = document.activeElement.selectionStart;
            }
        }
 
        function responseEnd(sender, args) {
            var element = document.getElementById(requestInitiator);
            if (element && element.tagName == "INPUT") {
                element.focus();
                element.selectionStart = selectionStart;
            }
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="requestStart" ClientEvents-OnResponseEnd="responseEnd">
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="true">
        <MasterTableView AutoGenerateColumns="false">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" FilterDelay="100"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="FirstName" FilterDelay="100"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</telerik:RadAjaxPanel>

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Kurt
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or