1. #1
    Sencha User
    Join Date
    Apr 2010
    Posts
    78
    Vote Rating
    1
    kskrumpet is on a distinguished road

      1  

    Default Working with nested models and editable grids

    Working with nested models and editable grids


    Note: I've drastically simplified the model in the description below to make this problem easier to understand.

    If I have a 1 level model (let's say of users), I can easily create an editable grid that displays and allows edit of all the singleton attributes in the model (name, phone number, etc.)

    Now what I'm trying to do is allow association of a hasMany set of records through the same grid. Each user has a number of widgets - the available widgets for any given user actually change depending on a number of things, so don't offer "use a static list" as a solution. So now my model is "Users" with a hasMany association to a second model "Widgets".

    To display the widgets that a user has within a single cell in the grid isn't so hard - just create a renderer that builds the string based on user.widgets(). But what I'd really like is to be able to edit that cell with a multiselect combobox that allows me to change the associated widgets for any given user in the grid.

    Any ideas?

    Or any offers of a solution to accomplish the same thing without using too much screen real-estate?

  2. #2
    Sencha User
    Join Date
    Apr 2010
    Posts
    78
    Vote Rating
    1
    kskrumpet is on a distinguished road

      0  

    Default


    Any thoughts?

  3. #3
    Sencha User
    Join Date
    Apr 2010
    Posts
    78
    Vote Rating
    1
    kskrumpet is on a distinguished road

      0  

    Default


    Ok, figured out a workaround.

    In my model:
    Code:
        getManyAsString: function(field) {
          var sl = "";
          var va = [];
          this[field]().each(function(item) {
            va[va.length] = item.get('value');
          });
          sl = va.join(", ");
          return sl;
        },
        setManyField: function(field, items) {
          var fstore = this[field]();
          fstore.removeAll();
          for (var i in items) {
            if (typeof items[i].data != "undefined") {
              fstore.add(items[i].data);
            }
          }
          fstore.sync();
        },
    In my store column def:

    Code:
          dataIndex: 'slwidgets',  // This is a dummy flat map field which contains the same as record.getManyAsString('widgets') provides
          renderer: function(value, p, record) {
            return record.getManyAsString('widgets'); // This shows a flat map of what's really in the model - technically not required
          },
    In the editable grid cell editing plugin:
    Code:
              validateedit: function(thisobj, e) {
                 e.record.setManyField('widgets', e.column.field.picker.selModel.getSelection();
    (Note: Quite a lot of code striped out and modified, so this may or may not work in your context; remember I said I was posting a problem that was significantly simplified than what I'm actually doing - the point is I have it working now).

    Rich
    ExtJS Developer, amongst other things: http://wintermedia.co.uk/extjs-consultancy

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi