Results 1 to 7 of 7

Thread: binding grid selection - what if I deselectAll() ?

    Success! Looks like we've fixed this one. According to our records the fix was applied for a bug in our system in a recent build.
  1. #1
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135

    Default binding grid selection - what if I deselectAll() ?

    I don't know if this is a bug or how should I handle this properly.

    Scenario:

    - a grid with a ViewModel
    - a form sharing the same ViewModel
    - form title & fields are bound to grid.selection

    Everything works fine while selecting rows in the grid.

    The issue appears when user deselects all rows in the grid (click bellow the last grid row)
    The form still has the last values but there's NO selected record in the grid !

    Same thing with the title bind. How can I reset the title if no rows are selected (using bind) ?

    If after you deselected all rows, edit any of the fields, select back rows, when deselecting again the previously edited field seems to be emty now (no matter what was the value after edit)....

    PS: I use this with two grids / stores associated (parent / child), but the same thing happens: child store remains filtered on the last selected parent record after deselectAll().

    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  2. #2
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135

    Default

    nothing on this one ?

    if I use selectionchange event on the grid and check if nothing is selected how can I empty child grid with it's filtered data ?

    If I do childStore.removeAll() while using session, I will not see those anymore...
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Location
    Lawrence, KS
    Posts
    462

    Default

    razvanioan,

    Thank you for an excellent test case. This seems like it would be a fairly common use case, so we're discussing this internally. Apparently, the bind doesn't attempt to evaluate on the deselection because the "chain" is broken. That process is currently required for digesting async data.

    Until we figure out how to proceed, you could do something along these lines:
    https://fiddle.sencha.com/#fiddle/b74

    Thanks!
    Greg

  4. #4
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135

    Default

    Thanks Greg,

    Nice (working) solution for form case.
    But as stated, my first BUMP on this is two grids (parent - child records).

    There I cannot do anything (as I've tried):

    - if I specify childGrid.getStore().removeAll() - to remove the filtered records of the child grid, then I will never see those records when reselecting that parent record....I'm using a data.session()
    - same thing hapened if I've added manually a filter on child store on some unexisting ID (like 0)
    - tried also setBind({store:null}), but this breaks the initial bound, so I have to manually readd it on businessLogic in case if...

    Tried even a not so clever solution: grid.removeAll() which does something else, and which by the way I think has another bug, it raises an error:

    Uncaught TypeError: Cannot read property 'getScrollLeft' of null

    Check this fiddle fork (press grid tbar button with JS console open): https://fiddle.sencha.com/#fiddle/b78
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  5. #5
    Sencha User
    Join Date
    Dec 2012
    Posts
    18

    Default

    It's true, feature with reset of selection and form on deselection via binding is really required in every day work.But I've found a simple decision. To create formula with bind on selection record, and to return non-existing id in get() function if there is no selected record.

    Code:
    formulas: { 
      parent_id: {  
        bind: '{parent.selection}',    
        get: function(record) {      
          return record ? record.get('id') : -1;     
        }
     }
    }

  6. #6
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135

    Default

    Hi ka-reon,

    Seems interesting, but haven't figured it out how / would you use it ...
    Can you enlighten me on my example / fiddle ?

    Couldn't figure it our myself
    At least for my scenario: two grids (one filtered by parent's selection)....

    Actually the formula works when bind to parent.selection (it outputs the correct values, and -1 when deselected parent rows), but don't know how to use it to filter the child grid....

    As on the chid grid I have store bind '{parent.selection.childStore}' but it doesn't uses my formula though....
    I suppose I'll have to manually use child store filter based on formula result....I'll try that !

    Thanks !
    ---
    Razvan Ioan ANASTASESCU
    Senior WEB Developer

  7. #7
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,257

    Default

    This is fixed in 5.1.0, when the parent is nulled out (the selection) it cascades down to any children for them to reevaluate.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •