View Full Version : [CLOSED] Lose focus on store data

Feb 04, 2015, 1:23 PM

I need to make a form like Excel that user can move cursor up and down with TAB key.

My code:

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
if (!X.IsAjaxRequest)
this.Store1.DataSource = new object[]
new object[] { 1, 1 },
new object[] { 2, 2 },
new object[] { 3, 3 },
new object[] { 4, 4 },
new object[] { 5, 5 },

<script type="text/javascript">
var CheckValue = function (el, e) {
var Value = this.getValue();
if (Value == 1)
if (!(Value == 2 || Value == 3 || Value == 4 || Value == 5)) {

el.record.set(el.dataIndex, Value);

<!DOCTYPE html>

<head id="Head1" runat="server">

<style type="text/css">
.x-grid .row-cmp-cell-ct td {position: relative; border-left: 1px solid #b5b8c8 !important; border-right: 1px solid #b5b8c8 !important; vertical-align: middle !important;}
.x-field-buttons-body .x-btn-icon {position: absolute; top: 0px; right: 2px;}

.x-grid-row-alt .x-grid-td,
.x-grid-row-alt .x-form-text {background-color: #eeeeee; background-image: none;}

<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:GridPanel ID="GridPanel1" runat="server" Title="Example" Width="500" Height="200">
<ext:Store ID="Store1" runat="server">
<ext:Model ID="Model1" runat="server">
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Number" Type="Int" />
<ColumnModel ID="ColumnModel1" runat="server">
<ext:Column runat="server" Text="ID" Width="200" DataIndex="ID" />
<ext:ComponentColumn runat="server" Text="Text" Flex="1" >
<ext:TextField runat="server" ItemID="TextFieldValue" EnableKeyEvents="true" SelectOnFocus="true" EnforceMaxLength="true" MaxLength="1" DataIndex="Number">
<ext:Button runat="server" Icon="Add" Hidden="true" />
<Change Fn="CheckValue" />
<BeforeBind Handler="var value = e.record.data.Number; if (value > 0 && value < 6) e.config[0].value = value; if (value == 1) e.config[0].rightButtons[0].hidden=false;" />
<Bind Handler="cmp.record = record;" />

<ext:Window runat="server" ID="Windows1" Title="Details" Hidden="true" >
<ext:TextField runat="server" ID="TextField1" />

In this code I can move up and down with the TAB key, but if I enter a value in the cell I lose the TextField control focus and the TAB key no longer works well.

But if I remove this line of code:

el.record.set(el.dataIndex, Value);

...the code works well and even if I press a number I do not lose the TextField control focus from the cell and with the TAB key you can move up or down.

Yet it not send postback and all the work is done by javascript.

Can you help me please?


Feb 04, 2015, 3:52 PM
Hi Mario,

Please try to replace:

el.record.set(el.dataIndex, Value);

el.record.data[el.dataIndex] = Value;

A record's set call re-renders a row. It is why the focus is being lost. I think that in your scenario you can just change a record's data silently.

Feb 04, 2015, 4:31 PM
Great Daniil ... it works!

I take advantage of your kindness yet:
if the grid was bigger, do you think it is possible to implement a solution using the keys Up, Down, Left and Right?

If you need I open a new thread for this question ....

Thank You

Feb 06, 2015, 12:36 PM
Personally, I would prefer a new forum thread.