<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamic column sizing dgrid (fit content) in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8197#M775</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know this thread is old, but I thought I'd reply with a solution in case anyone is still scratching their head on this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to dynamically size the columns based on the length of the header titles you'll need to put the string in an empty (invisible) span, measure the span, add some margin value and then use that as your column width. I used the ColumnResizer mixin so the sizing happens through the resizeColumnWidth() method. the dojoObject.forIn() method comes from dojox/lang/functional/object as a way to iterate over an associative array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fitColumns: function (grid) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojoObject.forIn(grid.columns, function (item) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var node = domConstruct.toDom('&amp;lt;span style="position:absolute;visibility:hidden"&amp;gt;' + item.label + '&amp;lt;/span&amp;gt;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domConstruct.place(node, grid.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var p = domGeom.position(node);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domConstruct.destroy(node);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grid.resizeColumnWidth(item.id, p.w + 8);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Dec 2014 21:26:15 GMT</pubDate>
    <dc:creator>RyanKoehnen</dc:creator>
    <dc:date>2014-12-23T21:26:15Z</dc:date>
    <item>
      <title>Dynamic column sizing dgrid (fit content)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8193#M771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a dgrid as seen here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]31111[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want the Title and Last Save columns to auto adjust to fit the widest cell without wrapping, thus leaving as much width as possible for the Description. I don't want to set the widths with css for a couple reasons: 1) what's the point if dynamic widths are the goal, and 2) the user can adjust the application font size.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If anyone knows how this might be easily accomplished or has a suggestion I'd appreciate it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 15:07:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8193#M771</guid>
      <dc:creator>BenFousek</dc:creator>
      <dc:date>2014-02-04T15:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic column sizing dgrid (fit content)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8194#M772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an article from Sitepen regarding CSS styling of dgrid:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="https://www.sitepen.com/blog/2012/05/03/css-styling-of-dgrid/"&gt;https://www.sitepen.com/blog/2012/05/03/css-styling-of-dgrid/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this doesn't answer your question, you might want to refer to the dgrid help page, since this isn't a specific JSAPI question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://dojotoolkit.org/community/"&gt;http://dojotoolkit.org/community/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 15:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8194#M772</guid>
      <dc:creator>JonathanUihlein</dc:creator>
      <dc:date>2014-02-04T15:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic column sizing dgrid (fit content)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8195#M773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jon,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm aware of dgird's styling. Can't seem to find any examples of content fitting. I'll hit up dojo for an answer too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ben&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 15:41:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8195#M773</guid>
      <dc:creator>BenFousek</dc:creator>
      <dc:date>2014-02-04T15:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic column sizing dgrid (fit content)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8196#M774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No problem!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;While I haven't had to do specifically what you are asking, I do know that you'll have to use width:auto; on your description column. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You might have to assume a maximum width for at least one column, which would let the others resize dynamically based on the remaining viewport width.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 16:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8196#M774</guid>
      <dc:creator>JonathanUihlein</dc:creator>
      <dc:date>2014-02-04T16:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic column sizing dgrid (fit content)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8197#M775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know this thread is old, but I thought I'd reply with a solution in case anyone is still scratching their head on this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to dynamically size the columns based on the length of the header titles you'll need to put the string in an empty (invisible) span, measure the span, add some margin value and then use that as your column width. I used the ColumnResizer mixin so the sizing happens through the resizeColumnWidth() method. the dojoObject.forIn() method comes from dojox/lang/functional/object as a way to iterate over an associative array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fitColumns: function (grid) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojoObject.forIn(grid.columns, function (item) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var node = domConstruct.toDom('&amp;lt;span style="position:absolute;visibility:hidden"&amp;gt;' + item.label + '&amp;lt;/span&amp;gt;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domConstruct.place(node, grid.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var p = domGeom.position(node);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domConstruct.destroy(node);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grid.resizeColumnWidth(item.id, p.w + 8);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Dec 2014 21:26:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamic-column-sizing-dgrid-fit-content/m-p/8197#M775</guid>
      <dc:creator>RyanKoehnen</dc:creator>
      <dc:date>2014-12-23T21:26:15Z</dc:date>
    </item>
  </channel>
</rss>

