Results 1 to 6 of 6

Thread: Bind ViewModel Data and store to Grid Template

  1. #1

    Default Answered: Bind ViewModel Data and store to Grid Template

    I'm using Ext.grid.Panel in conjunction with ViewModel. In ViewModel I have defined a store which is bound to store in the grid.

    However, in addition to store, I also have data in the ViewModel which I would like to reference in the grid template.


    How can I bind data and store in the ViewModel to grid data and reference both in the Template?
    http://www.dev4.life - Software Development Blog

  2. this schould work.

    Code:
    {
        xtype: 'templatecolumn',
        defaultRenderer: function(value, meta, record) {
            const myData = this.ownerCt.grid.lookupController().getViewModel().getData();
            const data = Ext.apply(myData, record.data, record.getAssociatedData());
            return this.tpl.apply(data);
        },
        tpl: '....'
    },

  3. #2

    Default

    One way I was thinking of accomplishing this is by injecting the additional data into each store record but I'm hoping there might be a better way of doing this.
    http://www.dev4.life - Software Development Blog

  4. #3
    Sencha User
    Join Date
    Aug 2017
    Posts
    18
    Answers
    3

    Default

    Quote Originally Posted by hitman01 View Post
    One way I was thinking of accomplishing this is by injecting the additional data into each store record but I'm hoping there might be a better way of doing this.
    Hi,

    i think its not inteded that you use other data then what the records includes in a template.


    Code:
    tpl: [
                    '{name} {[this.getExtraData()]}',
                    {
                        getExtraData: function () {
                            const data = this.owner.grid.getController().getViewModel().getData();
                            // do your work
                        },
                    }
                ]

  5. #4

    Default

    This would be perfect answer, except that this.owner is undefined!

    Any other way to achieve this?
    http://www.dev4.life - Software Development Blog

  6. #5
    Sencha User
    Join Date
    Aug 2017
    Posts
    18
    Answers
    3

    Default

    this schould work.

    Code:
    {
        xtype: 'templatecolumn',
        defaultRenderer: function(value, meta, record) {
            const myData = this.ownerCt.grid.lookupController().getViewModel().getData();
            const data = Ext.apply(myData, record.data, record.getAssociatedData());
            return this.tpl.apply(data);
        },
        tpl: '....'
    },

  7. #6
    Sencha User
    Join Date
    Aug 2017
    Posts
    18
    Answers
    3

    Default

    you can also use this.ownerCt.grid.lookupViewModel().getData();

Tags for this Thread

Posting Permissions

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