[CLOSED] CellEditing startEdit after adding new record

  1. #1

    [CLOSED] CellEditing startEdit after adding new record

    Hi I have an issue when adding a new record to the grid. I want to start editing the row straight away. In the example this works the first time around when pressing the "add" button. The second time around (pressing add again) results in the startEdit opening the correct cell for edit but then about half a second later it reverts back to the previous line. Working Example
                  Simple Array Grid - Ext.NET Examples                                      Simple Array Grid
    This may have something to do with not setting the IDProperty of the model. If I modify the add function to insert a numer into the "companyId" of the model then it works. However, my working copy is a batched grid and I don't want to insert any data as my server side code expects a "0" in the ID so that it knows it is a new record. Thanks Glen
    Last edited by Daniil; Nov 14, 2014 at 4:34 AM. Reason: [CLOSED]
  2. #2
    Hi Glen,

    An IDProperty field has to be unique on client side.

    I am curious why your batched grid doesn't recognize new records without the zero condition.

    In your example after adding some rows and call the Store's .getChangedData() and .getNewRecords() it returns the correct data, i.e. new records.
  3. #3
    Hi Danill

    This grid is part of the big batch save as mentioned in a previous post. The grid also uses row-reordering so once a record is moved all sortindexes change so I have opted to just send all data back. A "0" in the IDProperty indicates that it is a new record server side.

    To me it sort of looks like a bug....if you debug the code it actually finds the record based on the internalId of the model so it is working. However, there is something else that happens after the .startEdit code completes that resets it back to the first row added.

    I would've thought empty/zero IDProperty was kind of common? No matter I can use negative numbers to get around this but I have this occuring in multiple stores in my project and it just seemed like there should be a better way.

    Thanks
    Glen
  4. #4
    Hi Danill

    Actually setting the IDProperty to a negative number sets the phantom property to false. What is the correct use of adding records client side?

    Kind Regards
    Glen
  5. #5
    Hi Daniil

    Firstly apologie for misspelling your name :) (only just noticed). I've run the same example against native extjs scripts and the problem doesnt occur within their framework so I imagine it has something to do with the Ext.net build.

    The adding of negative id's doesnt really work for me as it modifies the phantom record to be false which is incorrect. I have got a solution to which I am running delayed task to startEditing 500ms after the add record. However, this is not a great work around as the grid appears to be jumping around from record to record.

    Hopefully you could look into this further.

    Kind Regards
    Glen

    https://fiddle.sencha.com/#fiddle/d6q
    Last edited by glenh; Nov 11, 2014 at 11:51 PM.
  6. #6
    Firstly apologie for misspelling your name :)
    No problem! Seems I didn't even notice that initially:)

    Actually setting the IDProperty to a negative number sets the phantom property to false.
    Yes, if a record's id is set by developer, it is not treated as a new record.

    I've run the same example against native extjs scripts and the problem doesnt occur within their framework so I imagine it has something to do with the Ext.net build.
    That finally leads me to think that something is wrong indeed.

    The main problem is the fact that an idProperty field must be unique even for new (phantom) records. Record ids are not generated automatically, I've totally forgot that. Honestly, I am curious why it is not generated automatically. I would expect it should. As it is in ExtJS 5. In any way, it is not in ExtJS 4. So, they (ExtJS team) have left it for a developer.

    Please use a Model's idgen.
    http://docs-origin.sencha.com/extjs/...odel-cfg-idgen
    http://docs-origin.sencha.com/extjs/...ta.IdGenerator

    If you need negatives, I can recommend the following.
    <ext:Model ID="Model1" runat="server" IDProperty="companyId">
        <IDGen>
            <ext:CustomIdGenerator>
                <CustomConfig>
                    <ext:ConfigItem Name="seed" Value="-1" Mode="Raw" />
                </CustomConfig>
                <GetRecId Handler="return record.modelName + '-' + record.internalId;" /> <%-- This is just a default one --%>
                <Generate Handler="return this.seed--;" />
            </ext:CustomIdGenerator>
        </IDGen>
        <Fields>
            <ext:ModelField Name="companyId" Type="Int" />
            ...
        </Fields>
    </ext:Model>
  7. #7
    Hi Daniil

    Excellent, as always thank you for the great solution!! This has acutally cleaned up a few other things for me as well such as not having to pass back the internalId.

    store.getChangedData({ skipIdForPhantomRecords: false })
    Then not having to find the record by the internal id after doing the save

    var model = store.getByInternalId(phantomid);
    Regards
    Glen
  8. #8
    Nice it helped you!

    Can we consider the thread closed?
  9. #9
    Yes...thanks!

Similar Threads

  1. [CLOSED] Adding new record with GridPanel and FormPanel
    By ermanni.info in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Apr 27, 2014, 9:58 PM
  2. [CLOSED] Adding New Record at run time
    By jesperhp in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 27, 2012, 12:17 PM
  3. [CLOSED] [1.0] Store adding record
    By state in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Dec 11, 2009, 6:24 PM
  4. [CLOSED] Adding a new Store Record - Not a Record object
    By Steve in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 15, 2009, 7:40 AM
  5. Adding one record in a grid
    By nuno_Santos in forum 1.x Help
    Replies: 1
    Last Post: Apr 14, 2009, 5:55 PM

Posting Permissions