Note that there are some explanatory texts on larger screens.

plurals
  1. POSencha Touch: filter dataview store with nested JSON data based on button click
    primarykey
    data
    text
    <p>I have a dataview list that fetches data from the server, puts it in a store, and renders into a template. Standard stuff.</p> <p>Above the dataview list in the UI is a button bar containing some Ext.Buttons. I want to be able tap a button and filter the list based on the name of the button. For example: click on 'English 9A' button and show items in the list with the '<strong>title</strong>' of 'English 9A'.</p> <p>As of now when I click the button, the list disappears and I get a console error of: "Uncaught TypeError: Cannot read property 'position' of undefined " and a loading spinner where the list was.</p> <p>I know there are similar questions out there but I've tried all the solutions but no luck at all.</p> <p>Sample json data:</p> <pre><code>{ "ftype":"Announcement", "value":{ "created":"7/18/2013 05:40:06 PM", "content":"Hello class, it is July 29th. This is quiz", "announcementtypename":"HW", "announcementtypeid":2, "expiresdate":"2013-07-19", "isowner":false, "gradable":false, "starred":false, "id":172459, "order":1, "state":1, "statetyped":1, "qnacount":0, "attachmentscount":0, "ownerattachmentscount":0, "title":"Spanish 9A", } }, { "ftype":"Announcement", "value":{ "created":"7/18/2013 12:04:45 PM", "content":"Hello class, it is July 18th. Here is an essay", "announcementtypename":"HW", "announcementtypeid":2, "expiresdate":"2013-07-19", "isowner":false, "gradable":false, "starred":false, "id":172009, "order":61, "state":1, "statetyped":1, "qnacount":0, "attachmentscount":0, "ownerattachmentscount":0, "title":"English 9A", } } </code></pre> <p>Model:</p> <pre><code>Ext.define('app.model.FeedModel', { extend: 'Ext.data.Model', config: { sorters: 'title', fields: [ {name: 'content', type: "string"}, {name: 'created', type: "string"}, {name: 'announcementtypename', type: "string"}, {name: 'announcementtypeid', type: "integer"}, {name: 'attachmentscount', type: "integer"}, {name: 'applicationscount', type: "integer"}, {name: 'ftype', type: "string"}, {name: 'title', type: "string"}, {name: 'expiresdate', type: "string"}, {name: 'starred', type: "boolean"} ] } }); </code></pre> <p>Store:</p> <pre><code>Ext.define('app.store.FeedStore',{ extend: 'Ext.data.Store', config:{ storeId:'FeedStore', model:'app.model.FeedModel', filterRoot: 'title', // * --does nothing filters: [ { property: 'title' // * --does nothing } ], } }); </code></pre> <p>Controller: (Needs the help)</p> <pre><code>//the button name matches the "title" node in the json filterFeedFunc: function(button){ var name = button.config.name; var sto = Ext.getStore('FeedStore'); var all = "allname"; if (name == all){ sto.clearFilter(); // when they click "all" it should show all items - doesn't work } //sto.clearFilter(); // * --doesn't work //sto.filter('title', name); // * --doesn't work sto.filter({ property: 'title', // * --doesn't work, need something new here value: name, exactMatch: true }); sto.load(); // no }, </code></pre> <p><strong>UPDATE / EDIT</strong></p> <p>the View:</p> <pre><code>Ext.define('app.view.feed.Feed', { extend: 'Ext.dataview.List', xtype: 'Feed', alias: 'widget.feedlist', config: { cls: 'feedlist', store : 'FeedStore', model: 'FeedModel', title:'', emptyText:'no items', style: 'background-color:#ffffff', itemTpl: new Ext.XTemplate( '&lt;tpl for="."&gt;'+ '&lt;div class="feed-item-box"&gt;'+ '&lt;tpl if="values.starred == true"&gt; &lt;img src="img/Important.png"&gt; &lt;/tpl&gt;'+ '&lt;tpl if="!values.starred"&gt; &lt;img src="img/not-starred.png"&gt; &lt;/tpl&gt;'+ '&lt;div class="anntype"&gt;&lt;h1&gt;{announcementtypename} &lt;/h1&gt;&lt;/div&gt;' + '&lt;div class="classname"&gt;&lt;h2&gt;{title:ellipsis(30)} &lt;/h2&gt;&lt;/div&gt;' + '&lt;div class="content"&gt;&lt;h4&gt;{content:ellipsis(50)} {summary}&lt;/h4&gt;&lt;/div&gt;' + '&lt;tpl if="values.attachmentscount || values.applicationscount"&gt;&lt;div class="attachment-clip"&gt;&lt;/div&gt; &lt;/tpl&gt;' + '&lt;div class="due"&gt; ' + '&lt;h4&gt;{[this.dueInfo(values.expiresdate)]} &lt;/h4&gt;' + '&lt;/div&gt;' + '&lt;/div&gt;'+ '&lt;/tpl&gt;',{ getUrl: function(){ var store = Ext.getStore('UrlStore'); var url = store.last(); return url.data.url; }, dueInfo: function(date){ var origDate = moment(date).format("MMMM Do"); var today = moment().format("MMMM Do"); if (today.match(origDate)){ return "Today" } else{ return origDate } } }), listeners:{ refresh: function(records) { var me = this; var classes = Ext.getStore('ClassListStore')._data.items; me.setItems([{ cls : 'classbar', docked : 'top', xtype : 'dataview', inline: { wrap: false }, scrollable: { direction: 'horizontal', directionLock: true }, height : 101, html : '&lt;div class="select-all" style= "float: left"&gt;&lt;/div&gt;', itemTpl: ''.concat ( '&lt;tpl for="."&gt;', '&lt;div class="select-{id}"&gt;&lt;/div&gt;', '&lt;/tpl&gt;' ), store : Ext.getStore('ClassListStore'), model : 'app.model.ClassListModel', listeners:{ refresh: function(){ var bar = jQuery('.classbar'); function getUserRole(){ var store = Ext.getStore('UserStore'); store.load(); var userRole = store.last(); return userRole.data.roledescription; } if (getUserRole() != app.UserRoles.ADMIN){ for(var i = 0; i &lt; classes.length; i++){ var data = classes[i].data; var render = Ext.DomQuery.select('.classbar .select-' + data.id)[0]; var allbutren = Ext.DomQuery.select('.classbar .select-all')[0]; var button = new Ext.Button({ ui: 'chalk-light', text: data.name, renderTo: render, name: data.name, clazzId: data.id, cls: 'class-button', action: 'filterFeed', html: '&lt;img width="45" style="margin-top: -45px;" src="https://www.app.com/Course/GetIcon?courseInfoId=' + data.courseinfoid + '"/&gt;' + '&lt;div class="classnamer"&gt;' + data.name + '&lt;/div&gt;' }); var allbutton = new Ext.Button({ ui: 'chalk-light', text: 'All', renderTo: allbutren, name: 'allname', clazzId: 'someId', cls: 'class-button x-button-pressing', action: 'filterFeed', html: '&lt;img width="45" style="margin-top: -45px;" src="https://www.app.com/Content/images/common/course-icons/all.png"/&gt;' + '&lt;div class="classnamer"&gt;All&lt;/div&gt;' }); } } else{ bar.hide(); } } } } , { cls : 'feedbar', itemId : 'something', docked : 'top', xtype : 'panel', items:[ { xtype: 'panel', html:'Feed', cls: 'feedTitle' }, { xtype: 'button', action: 'feedAll', text: 'All', cls: 'allBtn', ui: 'chalk-light' //see feedController.all() }, { xtype: 'button', action: 'starred', cls: 'impBtn', ui: 'chalk-light', html: '&lt;img src="img/not-starred.png"&gt; &amp;nbsp; Important' } ] }] ); } } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload