HZFN.COM
welcome to my space
X
Welcome to:hzfn.com
Search:  
NAVIGATION - HOME

Am I using Grid.afteredit correctly?

Published by: wktd 2008-11-22
  • Jack,

    I want to post cell changes back to my application server as they happen. Grid.afteredit seems like the right place to do this. However I have to go through a couple of hoops to simply get at the new value - see the first two lines of the callback below.

    Am I doing this in the most effective way? Perhaps you could review the parameter list to the afteredit event - the new value does appear to be available when the event is fired.

    Secondly, is creating a new connection the best way to post the update?

    Thanks,

    Gordon

    this.grid = new Ext.grid.EditorGrid(divId, {
    ...
    });
    this.grid.on('afteredit', this.afterEdit, this, true);
    ...
    afterEdit : function(grid, row, field, rowIndex, columnIndex){
    var ed = this.grid.getColumnModel().getCellEditor(columnInd ex, rowIndex);
    var value = ed.getValue();

    var rowId = row.id;
    var url = this.jsonUrl+"update/";
    var conn = new Ext.data.Connection();
    conn.request({
    url: url,
    params: {
    pageUrl: getPageUrl(),
    rowId: rowId,
    field: field,
    value: value
    }
    });
    },


  • Does afteredit and validateedit occur before or after a cell's custom renderer?


  • The original intention was to give you the ability to validate the value before it was set. Unfortunately, it doesn't provide the value in the event, so that makes it kind of worthless. I have completely redone the events, and they will be much more useful. Here's the documentation. This will be in the next Rev.

    /**
    * @event beforeedit
    * Fires before cell editing is triggered. The edit event object has the following properties

    *

      * grid - This grid
      * record - The record being edited
      * field - The field name being edited
      * value - The value for the field being edited.
      * row - The grid row index
      Microsoft ADO .NET - Page 2::
      How to get multiple tables into a dataset · Data Paging without using Datagrid control · Merge Method · No data-aware events using DataGrid & DataSet
      http://www.pcreview.co.uk/forums/archive/forum-203-2.php
      HOME
      form•Z Forum: <b>TESSELLATION</b>::
      1- grid density according to the curvature ( a kind of adaptive meshing) .. ( front and back) was not constructed correctly (several little smooth faces,
      http://www.formz.com/forum2/messages/16/30203.html?1226085621
      HOME
      * column - The grid column index
      * cancel - Set this to true to cancel the edit or return false from your handler.
      * [/list]
      * @param {Object} e An edit event (see above for description)
      Logic Users Group - LUG Forum Thread Index - Mar 2002::
      Fri, 22 Mar 2002 at 11:52:13 AM 0000 GMT; #54412: GEN: Using logic as an Audio #54914: LAW Missing Matrix Grid Lines Mon, 1 Apr 2002 at 12:08:48 AM
      http://logic-users.org/forums/LUG-2002-Mar-threads.html
      HOME
      */
      "beforeedit" : true,
      /**
      * @event afteredit
      * Fires after a cell is edited.

      *

        * grid - This grid
        * record - The record being edited
        * field - The field name being edited
        * value - The value being set
        * originalValue - The original value for the field, before the edit.
        * row - The grid row index
        * column - The grid column index
        * [/list]
        * @param {Object} e An edit event (see above for description)
        */
        "afteredit" : true,
        /**
        * @event validateedit
        * Fires after a cell is edited, but before the value is set in the record. Return false
        * to cancel the change. The edit event object has the following properties

        *

          * grid - This grid
          * record - The record being edited
          * field - The field name being edited
          * value - The value being set
          * originalValue - The original value for the field, before the edit.
          * row - The grid row index
          * column - The grid column index
          * cancel - Set this to true to cancel the edit or return false from your handler.
          * [/list]
          * @param {Object} e An edit event (see above for description)
          */
          "validateedit" : true

        • in the meantime...

          I understand that the afteredit event is called before the new value is stored in the record.
          So how do I get the new value? I suppose it is hiding in the editor but how do I get to that editor?

          thanks.

          Hey, any progress on this question. I'm also unsure of how to use the call afterEdit


        • Thanks for the response, tryanDLS. I think the way I understand it now is:

          beforeedit -- occurs before the IPE in the cell would even initialize

          validateedit -- occurs after ie. user hits enter following changing a value in a cell's IPE, but before it's send to handlers/backend/datastore. Also let's say the user entered a value of 10, hit enter or clicked away. validateedit would check if value >= 5 and since it's not, sets cancel to true.

          afteredit -- as Jack described, after everything completes and ds is updated

          It's validateedit that I'm not 100% clear on, but I suspect it's somewhat like I figure.


        • The original intention was to give you the ability to validate the value before it was set. Unfortunately, it doesn't provide the value in the event, so that makes it kind of worthless. I have completely redone the events, and they will be much more useful. Here's the documentation. This will be in the next Rev.

          /**
          * @event beforeedit
          * Fires before cell editing is triggered. The edit event object has the following properties

          *

            * grid - This grid
            * record - The record being edited
            * field - The field name being edited
            * value - The value for the field being edited.
            * row - The grid row index
            * column - The grid column index
            * cancel - Set this to true to cancel the edit or return false from your handler.
            * [/list]
            * @param {Object} e An edit event (see above for description)
            */
            "beforeedit" : true,
            /**
            * @event afteredit
            * Fires after a cell is edited.

            ...etc
            */
            "validateedit" : true


            hi man, there is a way to get the data of other field in the same row?? exemple: a grid with ID,name columns .. you edit name column and get the ID data of the same row.. is it possible?

            thanks

          • In my case, validateedit is no good since it does a remote async call via DWR.

            So I'd like to be able to do a 'rollback' in afteredit, however, this doesn't work in my handler:

            record.data[e.field] = e.originalValue

            Any idea on how to reset the value in the cell/module afteredit to originalValue?


          • *record - The record being edited

            e.g.

            var otherValue = e.record.data['other-field'];


            thanks man!! i already tried to config the record etc.. no sucess!
            but now everything runs 100% ..thanks!


          • I used this example to implement back end field validation.
            http://yui-ext.com/forum/viewtopic.php?t=3439

            and that worked for me.


          • The validateedit allows you to intercept and cancel the edit so it occurs before. The afteredit fires after the edit completes. Since "completes" means updating the data store, which in turns notifies the grid of the change, it would be after the renderer has been called.


          • Thanks, Jack. It's becoming clearer -- although...


            The validateedit allows you to intercept and cancel the edit so it occurs before.


            beforeedit vs. validateedit? (as you can cancel the edit in beforeedit as well)


          • hi man, there is a way to get the data of other field in the same row?? exemple: a grid with ID,name columns .. you edit name column and get the ID data of the same row.. is it possible?

            thanks


            *record - The record being edited

            e.g.

            var otherValue = e.record.data['other-field'];


          • in the meantime...

            I understand that the afteredit event is called before the new value is stored in the record.
            So how do I get the new value? I suppose it is hiding in the editor but how do I get to that editor?

            thanks.


          • Wow, you are fast. :)


          • That's excellent - Thanks Jack


          • Perfect, reject does exactly what I need. Thanks!


          • I believe beforeEdit is so that you can stop the process before you even allow the user to edit the cell, for example, you might want to disallow an edit of the cell in a given row b/c some other value in the row means it shouldn't be editable.


          • shouldn't that be e.record.data[e.field] = e.originalValue; instead?

            Ext.data.Record also has a reject() method, so you should be able to doe.record.reject();in your handler too.





          • Earnings Reports a Tonic for Ailing 'Net Stocks
            NatWest and InterTrust Form Global Alliance To Provide E-Commerce On the Internet
  • You are looking at:hzfn.com's Am I using Grid.afteredit correctly?, click hzfn.com to home
    #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Am I using Grid.afteredit correctly? , Please add it free.
     
     Homepage | Add to favorites | Contact us | Exchange links | LOGIN | Site map | 
    Copyright© 2008 hzfn.com        Site made:CFZ