Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by hjshin on Jan 20, 2010 23:30
open dhtmlx forum
grid size vs grid column width

hellow~

when i set what mygrid.setInitWidths("70,*,*,*,*,*,*,*") in your sample - 'pro_column_size.html'
there are space on the right side.

it's fine when i set what mygrid.setInitWidths("70,50,50,50,50,50,50,50").
just has problem set with '*'.

please check this.

thanks.

Answer posted by Alex (support) on Jan 21, 2010 03:02

Hello,

to calculate column sizes correctly it is better to use "*" only for one column. 

Please check the sample http://dhtmlx.com/docs/products/dhtmlxGrid/samples/10_grids_manipulations/03_grid_auto_width.html

You can also define widths in percent. For example (for the pro_column_size.html): 

mygrid.setInitWidthsP("10,10,20,10,10,10,10,*");

Answer posted by hjshin on Jan 21, 2010 18:49

hello,

sure...i checked this sample but our customer want to use '*' for several columns not only for one column. 

and there are any space.

example.......like this.............mygrid.setInitWidths("50,*,*,*,*,*,*,*")

i had to solve this problem. so i saw the source...dhtmlgrid.js and just updated this part and use this file.

please check this!!

 

this.setColumnSizes=function(gridWidth){
 var summ = 0;
 var fcols = [];
 for (var i = 0;i < this._cCount;i++){
  if ((this.initCellWidth[i] == "*")&& !this._hrrar[i]){
   this._awdth=false;
   fcols.push(i);
   continue
 };
 if (this.cellWidthType == '%'){
  if (typeof this.cellWidthPC[i]=="undefined")
   this.cellWidthPC[i]=this.initCellWidth[i];
  this.cellWidthPX[i]=Math.floor(gridWidth*this.cellWidthPC[i]/100)||0
 }else{
  if (typeof this.cellWidthPX[i]=="undefined")
   this.cellWidthPX[i]=this.initCellWidth[i]
 };
 if (!this._hrrar[i])
  summ+=this.cellWidthPX[i]*1
 };
 if (fcols.length){
  var ms = Math.floor((gridWidth-summ)/fcols.length);

  if (ms < 0)
   ms=1;
  for (var i = 0;i < fcols.length;i++){
   var next=Math.max((this._drsclmW ? this._drsclmW[fcols[i]] : 0),ms)
   this.cellWidthPX[fcols[i]]=next;
   summ+=next
  };
  
   //hjshin-------------------->HERE
   if(gridWidth > summ){
    this.cellWidthPX[fcols[fcols.length-1]]=this.cellWidthPX[fcols[fcols.length-1]] + (gridWidth-summ);
    summ = gridWidth;
   }
   //-------------------------->

  this._setAutoResize()
 };
 this.obj.style.width=summ+"px";
 this.hdr.style.width=summ+"px";
 if (this.ftr)
  this.ftr.style.width=summ+"px";
 this.chngCellWidth();
 return summ
};

Attachments (1)
Answer posted by Stanislav (support) on Jan 22, 2010 02:11
It looks as good addition. We will include similar update in next version of grid.