[CLOSED] Blur problem on Gridpanel

  1. #1

    [CLOSED] Blur problem on Gridpanel

    Hi,

    I use blur event on gridpanel cells to make some calculations with every change. But blur just work with Tab key. Enter or mouse click works in second fire. How can I fix this problem?


    Note: I want to upload minimized project source code, but I couldn't upload zip file.

    Aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ExtNetGrid.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <%--<link href="Theme/style/efatura_portal.css" rel="stylesheet" />
        <script src="Theme/js/jquery-1.11.3.min.js"></script>--%>
    
        <script src="Theme/JavaScript1.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="rsmCreateInvoice" runat="server">
            </ext:ResourceManager>
            <ext:ObjectHolder ID="DataHolder" runat="server" />
            <ext:Store ID="store1" runat="server">
                <Model>
                    <ext:Model ID="mdlServiceInfo" runat="server">
                        <Fields>
                            <ext:ModelField Name="OrderNo" Type="Int" />
                            <ext:ModelField Name="ServiceItems" Type="String" />
                            <ext:ModelField Name="Amount" Type="Float" />
                            <ext:ModelField Name="UnitPrice" Type="Float" />
                            <ext:ModelField Name="DiscountRate" Type="Float" />
                            <ext:ModelField Name="DiscountAmount" Type="Float" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
    
            <ext:GridPanel
                ID="gpServiceInfo"
                runat="server"
                Width="910"
                Height="250"
                MarginSpec="0 0 10 10"
                Title="Service Info"
                AutoScroll="true"
                EnableColumnMove="false"
                StoreID="store1" AutoDataBind="true" FocusOnToFront="false">
                <Plugins>
                    <ext:CellEditing ID="CellEditing1" runat="server" ClicksToEdit="1" />
                </Plugins>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server" StyleSpec="background-color: #DFE8F6">
                        <Items>
                            <ext:FieldContainer runat="server" Layout="HBoxLayout" StyleSpec="background-color: #DFE8F6">
                                <Items>
                                    <ext:Button ID="btnAddRow" runat="server" Text="Add Row" Icon="Add">
                                        <Listeners>
                                            <Click Fn="addNewRowToServiceInfo" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:BoxSplitter runat="server" />
                                    <ext:Button ID="btnDeleteRow" runat="server" Text="Remove Row" Icon="Delete" Disabled="true">
                                        <Listeners>
                                            <Click Fn="removeServiceInfoRow" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:FieldContainer>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel>
                    <Columns>
                        <ext:RowNumbererColumn ID="RowNumbererColumn1"
                            runat="server"
                            Text="Order</br>No"
                            DataIndex="OrderNo"
                            Width="40"
                            ColumnWidth="1"
                            Align="Center"
                            Sortable="false">
                            <%--<SummaryRenderer Handler="return ((value === 0 || value > 1) ? '(' + value +' Tasks)' : '(1 Task)');" />--%>
                        </ext:RowNumbererColumn>
                        <ext:Column
                            ID="clmServiceItems"
                            runat="server"
                            Text="Goods/Service"
                            DataIndex="ServiceItems"
                            Flex="1"
                            Width="110"
                            Align="Left"
                            MenuDisabled="true"
                            ColumnWidth="1"
                            TabIndex="0" Sortable="false">
                            <Editor>
                                <ext:TextField ID="txfEditorServiceItems" runat="server" AllowBlank="false" SelectOnFocus="true" />
                            </Editor>
                        </ext:Column>
                        <ext:NumberColumn
                            ID="clmAmount"
                            runat="server"
                            Text="Amount"
                            DataIndex="Amount"
                            Flex="1"
                            Width="56"
                            MenuDisabled="true"
                            Sortable="False"
                            ColumnWidth="1"
                            TabIndex="1">
                            <Editor>
                                <ext:NumberField ID="nmfEditorQuantity" runat="server" AllowBlank="false" DecimalSeparator="," SelectOnFocus="true" MinValue="0" HideTrigger="true">
                                    <Listeners>
                                        <Blur Handler="updateTotal(#{gpServiceInfo});" />
                                        <SpecialKey Handler="if(e.getKey() == Ext.EventObject.ENTER){updateTotal(#{gpServiceInfo});};"/>
                                    </Listeners>
                                </ext:NumberField>
                            </Editor>
                        </ext:NumberColumn>
                        <ext:NumberColumn
                            ID="clmUnitPrice"
                            runat="server"
                            Text="Unit<br/>Price"
                            DataIndex="UnitPrice"
                            Flex="1"
                            Width="60"
                            MenuDisabled="true"
                            Sortable="False"
                            ColumnWidth="1"
                            DefaultValueMode="RenderExplicit"
                            TabIndex="3" Format="0.0,0000000000/i">
                            <Renderer Handler="return Ext.util.Format.number(value, '0.00########');">
                            </Renderer>
                            <Editor>
                                <ext:NumberField ID="nmfUnitPrice" runat="server" DecimalSeparator="," AllowBlank="false"
                                    MinValue="0" HideTrigger="true" DecimalPrecision="10">
                                    <Listeners>
                                        <Blur AutoDataBind="true" Handler="updateTotal(#{gpServiceInfo});" />
                                    </Listeners>
                                </ext:NumberField>
                            </Editor>
                        </ext:NumberColumn>
                        <ext:NumberColumn
                            ID="clmDiscountRate"
                            runat="server"
                            Text="Discount<br/>Rate%"
                            DataIndex="DiscountRate"
                            Flex="1"
                            Width="60"
                            MenuDisabled="true"
                            Sortable="False"
                            ColumnWidth="1"
                            TabIndex="3">
                            <Editor>
                                <ext:NumberField ID="nmfDiscountRate" runat="server" DecimalSeparator="," AllowBlank="false"
                                    MinValue="0" HideTrigger="true">
                                    <Listeners>
                                        <Blur AutoDataBind="true" Handler="updateTotal(#{gpServiceInfo});" />
                                    </Listeners>
                                </ext:NumberField>
                            </Editor>
                        </ext:NumberColumn>
                        <ext:NumberColumn
                            ID="clmDiscountAmount"
                            runat="server"
                            Text="Discount<br/>Amount"
                            DataIndex="DiscountAmount"
                            Flex="1"
                            Width="60"
                            MenuDisabled="true"
                            Sortable="False"
                            ColumnWidth="1"
                            TabIndex="5">
                            <Editor>
                                <ext:NumberField ID="nmfDiscountAmount" runat="server" DecimalSeparator="," ReadOnly="true">
                                    <Listeners>
                                        <Blur AutoDataBind="true" Handler="updateTotal(#{gpServiceInfo});" />
                                    </Listeners>
                                </ext:NumberField>
                            </Editor>
                        </ext:NumberColumn>
                    </Columns>
                </ColumnModel>
                <Listeners>
                    <SelectionChange Handler="App.btnDeleteRow.setDisabled(!selected.length);" />
                </Listeners>
               
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Javascript:

    data = { DiscountAmount: 0};
    
    function initializeAmountDataObject() {
        var grid = App.gpServiceInfo;
        var X = grid.headerCt.getVisibleGridColumns();
        for (var i = 4; i < X.length; i++) {
            if (X[i].dataIndex != "Amount" && X[i].dataIndex.indexOf("Amount") > -1) {
                data[X[i].dataIndex] = 0;
            }
        }
    
    }
    
    var addNewRowToServiceInfo = function () {
        var grid = App.gpServiceInfo;
        var X = grid.headerCt.getVisibleGridColumns();
        var rowCount = getGridRowCount(grid);
        var rowOrder = rowCount + 1;
        var colArr = {
            OrderNo: rowOrder,
            ServiceItems: "",
            Amount: 1,
            Unit: ""
        }
        for (var i = 4; i < X.length; i++) {
           
                colArr[X[i].dataIndex] = 0;
           
        }
    
        addNewRow(grid, colArr);
    }
    
    var getGridRowCount = function (grid) {
        var store = grid.getStore();
        var rowCount = store.count();
        return rowCount;
    }
    
    var addNewRow = function (grid, initialValues) {
        var store = grid.getStore();
        var rowCount = getGridRowCount(grid);
        grid.editingPlugin.cancelEdit();
        store.getSorters().removeAll();
        grid.getView().headerCt.setSortState();
    
        store.insert(rowCount, initialValues);
        grid.editingPlugin.startEdit(rowCount, 0);
    }
    
    var removeServiceInfoRow = function () {
        var grid = App.gpServiceInfo;
       
        removeRow(grid);
        var store = grid.getStore();
        if (store.count() > 0) {
            updateTotal(grid);
        }
    }
    
    var removeRow = function (grid) {
        var selectionModel = grid.getSelectionModel();
        var store = grid.getStore();
        grid.editingPlugin.cancelEdit();
        store.remove(selectionModel.getSelection());
        if (store.getCount() > 0) {
            selectionModel.select(0);
        }
    }
    
    var format = "0.0,00/i";
    var formatUnitPrice = "0.0,0000000000/i";
    Ext.util.Format.thousandSeparator = ".";
    Ext.util.Format.decimalSeparator = ",";
    
    var calculateAmount = function (grid) {
    
        var selectedRow = grid.getSelectionModel().getSelection()[0]; //get('ServiceAmount')
        var amountNum = selectedRow.get('Amount'); //Ext.getCmp('txfEditorQuantity').value;
        amountNum = amountNum == null ? 0 : amountNum;
    
        var unitPrice = selectedRow.get('UnitPrice'); //Ext.getCmp('txfUnitPrice').value;
        unitPrice = unitPrice == null ? 0 : unitPrice;
    
        var discountRate = selectedRow.get('DiscountRate'); //Ext.getCmp('txfDiscountRate').value;
        discountRate = discountRate == null ? 0 : discountRate;
    
        var discountAmount = 0;
        discountAmount = (amountNum * unitPrice * discountRate) / 100;
    
        if (isNaN(discountAmount)) {
            selectedRow.set('DiscountAmount', 0);
        }
        else {
            selectedRow.set('DiscountAmount', discountAmount);
        }
       
    };
    
    
    function updateTotal(grid) {
        if (grid.view.rendered && grid.getStore().count() > 0) {
       
            calculateAmount(grid);
           
        }
        else {
            //var input = Ext.getCmp('nmfEditorQuantity');
            //input.fireEvent('Blur', updateTotal(App.gpServiceInfo, App.fcnHiddenTotals));
        }
    }
    Last edited by yusuf; Jun 22, 2016 at 12:26 PM. Reason: Adding codes
  2. #2
    Hello @yusuf!

    Please, don't send links nor upload full project files. We'd require it to be the simplest test case possible in order to be able to reproduce the problem and meaningfully provide you a solution. Too much contents on a test case just drives everyone away from the real cause of the problem.

    I believe you could reproduce your issue with a much much simpler sample test case with maybe two or three fields, and it would be much clearer for us as to how to help you fix your problem.

    If you can come up with a simplified and running test case, please update the thread. We'll analyse your long test case but can't guarantee we'll be able to come up with a response in the short term.

    Here, useful text and links for coming up with a nice and shiny test case so we can best help you!

    ---
    The code sample you provide should include only the minimum amount of code required to reproduce the issue. Code unrelated to the issue is to be removed. Anyone should be able to copy + paste your sample into a local Visual Studio test project and run without having to make modifications.

    Tips for creating simplified code samples

    If Exceptions or syntax errors are thrown when testing your code sample, we'll let you know so you can revise your original sample. Then we'll review again with the updated sample.

    When posting your code samples in the forums, please paste that sample within [CODE] tags. The [CODE] tags will add formatting and syntax highlighting to your sample.

    The following two forum posts provide many excellent tips for posting in the forums:

    1. More Information Required
    2. Forum Guidelines

    ---

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello again, @yusuf!

    In your case it looks like you want to use the cell editing plugin's edit event.

    Something like this:

    <Plugins>
        <ext:CellEditing runat="server">
            <Listeners>
                <Edit Fn="cellEditHandler" />
            </Listeners>
        </ext:CellEditing>
    </Plugins>
    You can use the following prototype on cellEditHandler():

    var cellEditHandler = function (item, e) {
        ...
    }
    I hope this helps! There's also the cancel event on the cell editor, if you need to do some check ups even if the user cancelled editing the row (usually by hitting 'esc' on the field).
    Fabrício Murta
    Developer & Support Expert
  4. #4
    Thank you fabricio.murta. Your solution works like I want.
    I will keep in sight your warnings and information about thread rules in further questions.
  5. #5
    Hello @yusuf!

    Glad it worked for you! And thank you very much as those guidelines were thought such as it is "you helping us help us". As you get used to the forums and even read other threads with solutions it would become more natural as for ways to post simple samples that allows us to quickly reproduce the issue, possibly logging as a bug or just giving you a prompt answer for your question!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] gridpanel editor blur
    By CPA1158139 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 18, 2014, 1:33 PM
  2. [CLOSED] Help with blur for GridPanel please
    By GLD in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 06, 2011, 2:55 PM
  3. RemoteValidation help (not firing on second blur)
    By Tallmaris in forum 1.x Help
    Replies: 5
    Last Post: Jul 07, 2011, 12:06 PM
  4. send extra parameters on blur event of textfield editor inside gridpanel
    By aditya.murthy88@gmail.com in forum 1.x Help
    Replies: 2
    Last Post: Dec 11, 2010, 12:04 PM
  5. Replies: 4
    Last Post: Aug 16, 2010, 8:39 AM

Tags for this Thread

Posting Permissions