{"id":42,"date":"2012-09-15T23:17:00","date_gmt":"2012-09-15T23:17:00","guid":{"rendered":"http:\/\/tpodolak.com.hostingasp.pl\/blog\/2012\/09\/15\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/"},"modified":"2016-01-31T00:07:22","modified_gmt":"2016-01-31T00:07:22","slug":"extjs-4-1-1-how-to-fix-row-resize-phenomena","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2012\/09\/15\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/","title":{"rendered":"Extjs 4.1.1 &#8211; how to fix row resize phenomena"},"content":{"rendered":"<p>Recently I&#8217;ve encountered annoying problem with extjs grid. After hiding columns with long wrapped text, height of rows was dramatically increased. Here are some screens presenting this particular situation. Grid with all columns shown;<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problembeforeshow.jpg\" rel=\"attachment wp-att-398\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problembeforeshow.jpg\" alt=\"problembeforeshow\" width=\"250\"  class=\"aligncenter size-full wp-image-398\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problembeforeshow.jpg 319w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problembeforeshow-150x145.jpg 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problembeforeshow-300x291.jpg 300w\" sizes=\"(max-width: 319px) 100vw, 319px\" \/><\/a><br \/>\nand grid with one column hidden<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problemaftershow.png\" rel=\"attachment wp-att-397\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problemaftershow.png\" alt=\"row resize\"  height=\"300\" class=\"aligncenter size-full wp-image-397\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problemaftershow.png 240w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problemaftershow-66x150.png 66w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/problemaftershow-131x300.png 131w\" sizes=\"(max-width: 240px) 100vw, 240px\" \/><\/a><br \/>\nThe code responsible for rendering this grid is shown below<\/p>\n<pre lang=\"css\">\r\n.x-grid-cell-inner { white-space: normal; }\r\n<\/pre>\n<pre lang=\"javascript\">\r\nExt.onReady(function () {\r\n        Ext.QuickTips.init();\r\n        var store = Ext.create('Ext.data.Store', {\r\n            fields: ['Id', 'firstname', 'lastname'],\r\n            data: {\r\n                items: [{\r\n                    Id: 1,\r\n                    firstname: 'some long text some long text some long text some long text some long text some long text some long text some long text some long textareasome long textareasome long textarea',\r\n                    lastname: 'Smith'\r\n                },{\r\n                    Id: 1,\r\n                    firstname: 'Mat'\r\n                },{\r\n                    Id: 1,\r\n                    firstname: 'Kate',\r\n                    lastname: 'Smith'\r\n                },{\r\n                    Id: 1,\r\n                    firstname: 'Richard',\r\n                    lastname: 'Smith'\r\n                }]\r\n            },\r\n            proxy: {\r\n                type: 'memory',\r\n                reader: {\r\n                    type: 'json',\r\n                    root: 'items'\r\n                }\r\n            }\r\n        });\r\n\r\n       var visible = true;\r\n       var grid = Ext.create('Ext.grid.Panel', {\r\n            store: store,\r\n            renderTo: Ext.getBody(),\r\n            columns: [\r\n                      { text: 'Id', dataIndex: 'Id' },\r\n                      { text: 'First name', dataIndex: 'firstname' },\r\n                      { text: 'Last name', dataIndex: 'lastname' }]});\r\n\r\n        Ext.create('Ext.button.Button', {\r\n            text: 'click',\r\n            renderTo: Ext.getBody(),\r\n            handler: function() {\r\n                visible = !visible;\r\n                grid.columns[1].setVisible(visible);\r\n                grid.validate();\r\n            }\r\n        });\r\n    });\r\n<\/pre>\n<p>After some digging, it turned out that Extjs hides columns by setting their width to 0px. In order to solve this problem and preverse text wrap in cells, I implemented small workaround. Let&#8217;s start from creating CSS class which disables word wrapping in grid cells.<\/p>\n<pre lang=\"css\">\r\n.noWrap .x-grid-cell-inner {white-space: nowrap;}\r\n<\/pre>\n<p>Next, we have to start listening for two events<\/p>\n<ul>\n<li>columnhide<\/li>\n<li>columnshow<\/li>\n<\/ul>\n<p>In handlers of these events, we have to modify <i>tdCls<\/i> property of hidden column &#8211; add <i>noWrap<\/i> class, if column is hidden and delete this class otherwise.<\/p>\n<pre lang=\"javascript\">\r\ngrid.headerCt.on({\r\n            columnhide: function (headerCt, column) {\r\n                column.tdCls = \"noWrap\";\r\n                this.getView().refresh();\r\n            },\r\n            columnshow: function (headerCt, column) {\r\n                column.tdCls = \"\";\r\n                this.getView().refresh();\r\n            },\r\n            scope: grid\r\n        });\r\n<\/pre>\n<p>From now hiding and showing columns works fine<br \/>\n<a href=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/fixedAfterHide.png\" rel=\"attachment wp-att-395\"><img decoding=\"async\" src=\"http:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/fixedAfterHide.png\" alt=\"fixedAfterHide\" width=\"191\" class=\"aligncenter size-full wp-image-395\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/fixedAfterHide.png 191w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2012\/09\/extjs-4-1-1-how-to-fix-row-resize-phenomena\/fixedAfterHide-150x123.png 150w\" sizes=\"(max-width: 191px) 100vw, 191px\" \/><\/a><br \/>\nEntire code listing is presented below<\/p>\n<pre lang=\"javascript\">\r\nExt.onReady(function () {\r\n        Ext.QuickTips.init();\r\n        var store = Ext.create('Ext.data.Store', {\r\n            fields: ['Id', 'firstname', 'lastname'],\r\n            data: {\r\n                items: [{\r\n                    Id: 1,\r\n                    firstname: 'some long text some long text some long text some long text some long text some long text some long text some long text some long textareasome long textareasome long textarea',\r\n                    lastname: 'Smith'\r\n                },{\r\n                    Id: 1,\r\n                    firstname: 'Mat'\r\n                },{\r\n                    Id: 1,\r\n                    firstname: 'Kate',\r\n                    lastname: 'Smith'\r\n                },{\r\n                    Id: 1,\r\n                    firstname: 'Richard',\r\n                    lastname: 'Smith'\r\n                }]\r\n            },\r\n            proxy: {\r\n                type: 'memory',\r\n                reader: {\r\n                    type: 'json',\r\n                    root: 'items'\r\n                }\r\n            }\r\n        });\r\n\r\n       var visible = true;\r\n       var grid = Ext.create('Ext.grid.Panel', {\r\n            store: store,\r\n            renderTo: Ext.getBody(),\r\n            columns: [\r\n        { text: 'Id', dataIndex: 'Id' },\r\n        { text: 'First name', dataIndex: 'firstname' },\r\n        { text: 'Last name', dataIndex: 'lastname' }]});\r\n\r\n        grid.headerCt.on({\r\n            columnhide: function (headerCt, column) {\r\n                column.tdCls = \"noWrap\";\r\n                this.getView().refresh();\r\n            },\r\n            columnshow: function (headerCt, column) {\r\n                column.tdCls = \"\";\r\n                this.getView().refresh();\r\n            },\r\n            scope: grid\r\n        });\r\n\r\n        Ext.create('Ext.button.Button', {\r\n            text: 'click',\r\n            renderTo: Ext.getBody(),\r\n            handler: function() {\r\n                visible = !visible;\r\n                grid.columns[1].setVisible(visible);\r\n                grid.validate();\r\n            }\r\n        });\r\n    });\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve encountered annoying problem with extjs grid. After hiding columns with long wrapped text, height of rows was dramatically increased. Here are some screens presenting this particular situation. Grid with all columns shown; and grid with one column hidden The code responsible for rendering this grid is shown below .x-grid-cell-inner { white-space: normal; } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63,67,96],"tags":[203,210,233],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-ext-panel-grid","category-extjs-4-1-1","category-resize","tag-ext-panel-grid","tag-extjs-4-1-1","tag-resize"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":4,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":548,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions\/548"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}