ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Auto width for columns
Title:
B
I
{code}
?
I need to set the minimum width for some columns to such a value at which the data will completely fit into it without line breaks. Is there a way to automatically fit the columns widths using the library? My problem is that I do not know in advance the value to use for the width. I need to automatically set a width for the column so that all the data will fit.
Save Changes
Cancel
Evgeny Alekseev
asked at 07 Aug 2020
Answers
B
I
{code}
?
there is `Column.MinWidth` for minimum column width you can see it being used here: https://demo.aspnetawesome.com/GridDemo on the Food Column here's a js function that you can use to automatically set the min width for the columns depending on their content: $(function() { gridColAutoWidth('Grid1'); }); function gridColAutoWidth(gridId) { var g = $('#' + gridId); // data loaded g.on('aweload', function(e) { if (!$(e.target).is(g)) return; var colSizes = {}; var scale = $('<span class="awe-row"></span>'); g.find('.awe-content').append(scale); // calc col sizes g.find('.awe-itc .awe-row').each(function(i, rel) { $(rel).children().each(function(tdi, tdel) { // get content width scale.html($(tdel).html()); colSizes[tdi] = Math.max(colSizes[tdi] || 0, scale.width()); }); }); scale.remove(); // apply col sizes var columns = g.data('o').columns; g.find('colgroup').first().children().each(function(rendi, cel) { var coli = $(cel).data('i'); if (awef.isNotNull(coli)) { columns[coli].Mw = colSizes[rendi] + 50; // plus for padding } }); g.data('api').render(); }); }
Save Changes
Cancel
Omu
answered at 07 Aug 2020
The best, thx you!
at 10 Aug 2020
Evgeny Alekseev
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK