{"id":459,"date":"2012-09-03T23:12:55","date_gmt":"2012-09-03T23:12:55","guid":{"rendered":"http:\/\/garysieling.com\/blog\/?p=459"},"modified":"2012-09-03T23:12:55","modified_gmt":"2012-09-03T23:12:55","slug":"extjs-listview-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/extjs-listview-example\/","title":{"rendered":"ExtJS ListView Example"},"content":{"rendered":"<p><strong>Problem<\/strong><\/p>\n<p>You want to display a grid which lists a series of objects.<\/p>\n<p><a href=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2012\/09\/extjs-gridview-example.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-471\" title=\"extjs-gridview-example\" src=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2012\/09\/extjs-gridview-example.png\" alt=\"\" width=\"475\" srcset=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-gridview-example.png 552w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-gridview-example-300x218.png 300w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/a><\/p>\n<p><strong>Solution<\/strong><\/p>\n<p>Use a GridPanel (aka ListView):<\/p>\n<pre lang=\"javascript\">Ext.require([\n    'Ext.grid.*',\n    'Ext.data.*',\n    'Ext.util.*',\n    'Ext.state.*'\n]);\n\nExt.onReady(function() {\n    var trackStore = new Ext.data.Store({\n        storeId: 'soundCloudStore',\n\n        proxy: {\n            type: 'ajax',\n            url: 'blues.json',\n            reader: {\n                type: 'json',\n                idProperty: 'id'\n            }\n        },\n        fields:['duration', 'genre', 'created_at', 'kind', 'title', 'id']\n    });\n\n    trackStore.load(\n        function() { \n            Ext.create('Ext.grid.Panel', {\n                title: 'Tracks',\n                store: trackStore,\n                columns: [\n                    { header: 'Title', dataIndex: 'title' },\n                    { header: 'Duration',  dataIndex: 'duration' },\n                    { header: 'Genre', dataIndex: 'genre' },\n                    { header: 'Created At', dataIndex: 'created_at' },\n                    { header: 'Kind', dataIndex: 'kind' }\n                ],\n                height: 400,\n                width: 550,\n                renderTo: Ext.getBody()\n         });\n    });\n});<\/pre>\n<p><strong>Discussion<\/strong><\/p>\n<p>Most of the Ext examples for rendering grids show how to do it with static data &#8211; this is rarely what you want. This example loads JSON data copied from a call to an API outside our control, SoundCloud. Retrieving data across domains may require additional configuration.<\/p>\n<p>It&#8217;s important to set the &#8220;id&#8221; property in the proxy configuration, as Ext grids use this to uniquely identify rows.<\/p>\n<p>Make sure to initialize the page inside Ext.onReady and include the necessary script and CSS files (e.g. ext-all-debug.js and ext-all.css).<\/p>\n<p>ext-all.css is in resources\\css of the Ext distribution zip file. Ext-all-debug.js is in the root of the distribution.<\/p>\n<p>This must be run from a web server to work &#8211; the JSON requests will not work if the originating page is a file:\/\/ URL.<\/p>\n<p>GridPanel is the Ext4.0 name, and ListView is the 3.x name.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem You want to display a grid which lists a series of objects. Solution Use a GridPanel (aka ListView): Ext.require([ &#8216;Ext.grid.*&#8217;, &#8216;Ext.data.*&#8217;, &#8216;Ext.util.*&#8217;, &#8216;Ext.state.*&#8217; ]); Ext.onReady(function() { var trackStore = new Ext.data.Store({ storeId: &#8216;soundCloudStore&#8217;, proxy: { type: &#8216;ajax&#8217;, url: &#8216;blues.json&#8217;, reader: { type: &#8216;json&#8217;, idProperty: &#8216;id&#8217; } }, fields:[&#8216;duration&#8217;, &#8216;genre&#8217;, &#8216;created_at&#8217;, &#8216;kind&#8217;, &#8216;title&#8217;, &#8216;id&#8217;] }); &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/extjs-listview-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ExtJS ListView Example&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[211,216,218,262,322,341,502],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/459"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=459"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/459\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}