Jump to content

uniDbGrid Summary


rtalmeida

Recommended Posts

Hi,

 

At the moment you can use this approach I think, for example:

 

1. UniDBGrid1 -> OnColumnSummary:

procedure TMainForm.UniDBGrid1ColumnSummary(Column: TUniDBGridColumn;
  GroupFieldValue: Variant);
begin
  if SameText(Column.FieldName, 'quantity') then
  begin
    //not needed
  end;
end;

2. UniDBGrid1 -> OnColumnSummaryResult:

procedure TMainForm.UniDBGrid1ColumnSummaryResult(Column: TUniDBGridColumn;
  GroupFieldValue: Variant; Attribs: TUniCellAttribs; var Result: string);
var
  I, J : Integer;
  F : Real;
begin
  if SameText(Column.FieldName, 'quantity') then
  begin
    // needed only for change Attribs
    Attribs.Font.Style:=[fsBold];
    Attribs.Font.Color:=clGreen; 
  end;
end;

3. UniDBGrid1 -> ClientEvents -> ExtEvents -> function reconfigure:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    // 2 - your Column Index (zero based)
    columns[2].summaryRenderer = function(value, summaryData, dataIndex, metaData) {
        if (value && typeof value == "object") {
            
            var v = 0,
                va = value["_sa" + dataIndex],
                sty = null;
          
            sender.getSelectionModel().getSelection().forEach(function(sel){v += parseInt(sel.data[dataIndex])});
           
            if (va) {
                try {
                    eval("var fobj=" + va + ";")
                } catch (err) {
                    _log(err.message)
                }
                if (typeof fobj != "object") {
                    var fobj = {}
                }
                sty = fobj2style(fobj, false, true)
            }
            if (sty) {
                metaData.tdAttr = sty
            }
            return (v)
        }
        return ""
    }
}

4. UniDBGrid1 -> ClientEvents -> ExtEvents -> [Ext.selection.CheckboxModel [checkboxModel]] -> function checkboxModel.selectionchange:

function checkboxModel.selectionchange(sender, selected, eOpts)
{
    sender.view.refresh();
}

5. UniDBGrid1 -> OnAfterLoad:

procedure TMainForm.UniDBGrid1AfterLoad(Sender: TUniDBGrid);
begin
  Sender.JSInterface.JSCode('Ext.defer(function(){'#1'.getView().refresh()}, 100);');
end;

6. And of course dgMultiSelect = True and dgCheckSelect = True and ShowSummary = True

 

Result:

post-906-0-35290400-1501439297_thumb.png

 

Best regards,

  • Like 1
Link to comment
Share on other sites

Just one detail, it works only for integers? I changed parseInt to parsefloat but it made no difference.

 

parseFloat(sel.data[dataIndex])

return (v.toFixed(2))

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    columns[2].summaryRenderer = function(value, summaryData, dataIndex, metaData) {
        if (value && typeof value == "object") {
            
            var v = 0,
                va = value["_sa" + dataIndex],
                sty = null;
          
            sender.getSelectionModel().getSelection().forEach(function(sel){v += parseFloat(sel.data[dataIndex])});
            
            if (va) {
                try {
                    eval("var fobj=" + va + ";")
                } catch (err) {
                    _log(err.message)
                }
                if (typeof fobj != "object") {
                    var fobj = {}
                }
                sty = fobj2style(fobj, false, true)
            }
            if (sty) {
                metaData.tdAttr = sty
            }
            return (v.toFixed(2))
        }
        return ""
    }
}
Link to comment
Share on other sites

  • 2 years later...
29 minutes ago, freedowsRoO said:

Hey @Sherzod how are you? I need almost the same thing. I have a paged grid with totals and filters,  i need to refresh my  grid totals when the grid is filtered.

 

Is it possible?

Hello,

I'm fine, thank you. And you?

Can you make a simple test case to see the problem?

Link to comment
Share on other sites

1 hour ago, Sherzod said:

Hello,

I'm fine, thank you. And you?

Can you make a simple test case to see the problem?

 

Sorry i tried to make the test case but i don't managed because i use a FIREDAC component to connect with The database.

 

The problem is simple, i made a summary paged dbgrid following the demo and after that i add a collumn filter. My summary is ok but when i use the column filter i need to recalc the summary totals.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...