Jump to content

change forcefit true on unidbgrid to false when the screen resolution is small


Recommended Posts

Posted

how to change forcefit true on unidbgrid to false when the screen resolution is small such as a cellphone or tablet, so that the data in the column can be shifted to make it visible

ForceFit = True
image.thumb.png.a83fa27e8d02e5dd2d1ffbd3bfa746f8.png

 

when the screen resolution is small the data in the column becomes unclear

image.png.ceb1649faddea6856b9610068e52351b.png

Posted

I prefer to use columns lock property on mobile Example: For mobile unidbgrid1.columns[0].locked:=true; 

You can use this code on create event

or on create event 

if uniGUIApplication.UniSession.IsPhone then

unidbgrid1.forcefit:=false

Posted
19 hours ago, emin said:

I prefer to use columns lock property on mobile Example: For mobile unidbgrid1.columns[0].locked:=true; 

You can use this code on create event

or on create event 

if uniGUIApplication.UniSession.IsPhone then

unidbgrid1.forcefit:=false

still remains unchanged ForceFit

image.png

Posted
23 hours ago, Muhammad Idris said:

Hello,

Try this approach:

1. MainForm.Script ->

// Put this in MainForm.Script (or globally in ServerModule.CustomFiles)
Ext.override(Ext.grid.Panel, {
  /**
   * on = true  → forceFit = true; setFlex(1) for all non-locked columns; then setWidth(initialConfig.width)
   * on = false → forceFit = false; setFlex(0) for all non-locked columns; then setWidth(initialConfig.width)
   * Locked columns are: checkbox, row number, or columns marked with col.flexLock = true
   * Layouts are safely suspended/resumed with try/finally.
   */
  setForceFitSimple: function (on) {
    var g = this,
        v = g.getView && g.getView(),
        h = v && v.getHeaderCt && v.getHeaderCt(),
        cols = g.getColumnManager().getColumns(),
        suspended = false;

    try {
      // keep parity with console approach + update header state when available
      g.forceFit = (on === true);
      if (h && h.setForceFit) h.setForceFit(on === true);

      Ext.suspendLayouts();
      suspended = true;

      Ext.Array.each(cols, function (col) {
        // skip service/locked columns
        if (col.isCheckerHd || col.isRowNumberer || col.flexLock) return;

        if (on) {
          if (col.setFlex) col.setFlex(1);
          if (col.initialConfig && col.initialConfig.width != null)
            col.setWidth(col.initialConfig.width);
        } else {
          if (col.setFlex) col.setFlex(0);
          if (col.initialConfig && col.initialConfig.width != null)
            col.setWidth(col.initialConfig.width);
        }
      });
    } catch (e) {
      // optional: log the error; at minimum we still resume layouts in finally
      if (window.console && console.error) console.error('setForceFitSimple error:', e);
    } finally {
      if (suspended) Ext.resumeLayouts(true);
    }
  }
});

2. Usage ->

procedure TMainForm.UniFormResize(Sender: TObject);
begin
   //if UniSession.IsPhone then
   // unidbgrid1.forcefit:=false else unidbgrid1.forcefit:=true;

   if UniSession.IsPhone then
     UniDBGrid1.ForceFit := False else UniDBGrid1.ForceFit := True;

   UniDBGrid1.JSInterface.JSCall('setForceFitSimple', [UniDBGrid1.ForceFit]);
end;

 

Posted
On 8/30/2025 at 8:00 PM, Sherzod said:

Hello,

Try this approach:

1. MainForm.Script ->

// Put this in MainForm.Script (or globally in ServerModule.CustomFiles)
Ext.override(Ext.grid.Panel, {
  /**
   * on = true  → forceFit = true; setFlex(1) for all non-locked columns; then setWidth(initialConfig.width)
   * on = false → forceFit = false; setFlex(0) for all non-locked columns; then setWidth(initialConfig.width)
   * Locked columns are: checkbox, row number, or columns marked with col.flexLock = true
   * Layouts are safely suspended/resumed with try/finally.
   */
  setForceFitSimple: function (on) {
    var g = this,
        v = g.getView && g.getView(),
        h = v && v.getHeaderCt && v.getHeaderCt(),
        cols = g.getColumnManager().getColumns(),
        suspended = false;

    try {
      // keep parity with console approach + update header state when available
      g.forceFit = (on === true);
      if (h && h.setForceFit) h.setForceFit(on === true);

      Ext.suspendLayouts();
      suspended = true;

      Ext.Array.each(cols, function (col) {
        // skip service/locked columns
        if (col.isCheckerHd || col.isRowNumberer || col.flexLock) return;

        if (on) {
          if (col.setFlex) col.setFlex(1);
          if (col.initialConfig && col.initialConfig.width != null)
            col.setWidth(col.initialConfig.width);
        } else {
          if (col.setFlex) col.setFlex(0);
          if (col.initialConfig && col.initialConfig.width != null)
            col.setWidth(col.initialConfig.width);
        }
      });
    } catch (e) {
      // optional: log the error; at minimum we still resume layouts in finally
      if (window.console && console.error) console.error('setForceFitSimple error:', e);
    } finally {
      if (suspended) Ext.resumeLayouts(true);
    }
  }
});

2. Usage ->

procedure TMainForm.UniFormResize(Sender: TObject);
begin
   //if UniSession.IsPhone then
   // unidbgrid1.forcefit:=false else unidbgrid1.forcefit:=true;

   if UniSession.IsPhone then
     UniDBGrid1.ForceFit := False else UniDBGrid1.ForceFit := True;

   UniDBGrid1.JSInterface.JSCall('setForceFitSimple', [UniDBGrid1.ForceFit]);
end;

 

still can not

image.png.2ebba65916973af5e0e0ef2378c38613.png

DbgridForceFit_1.zip

Posted
1 hour ago, Muhammad Idris said:

still can not

I can’t directly test your test case since I don’t have TVirtualTable. But that’s not important, I was able to test it with a simple demo example, and it works for me.

And from your screenshot it actually looks like forceFit is applied — columns are stretched to fit the grid width (desktop mode). With forceFit=false you would see fixed widths and a horizontal scrollbar...

Posted
On 9/1/2025 at 3:39 PM, Sherzod said:

I can’t directly test your test case since I don’t have TVirtualTable. But that’s not important, I was able to test it with a simple demo example, and it works for me.

And from your screenshot it actually looks like forceFit is applied — columns are stretched to fit the grid width (desktop mode). With forceFit=false you would see fixed widths and a horizontal scrollbar...

Could you please send a sample application? Thank You

Posted
Quote

I prefer to use columns lock property on mobile Example: For mobile unidbgrid1.columns[0].locked:=true; 

You can use this code on create event

or on create event 

if uniGUIApplication.UniSession.IsPhone then

unidbgrid1.forcefit:=false

Can you try this again

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...