Jump to content

Recommended Posts

Posted

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
Posted

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 ""
    }
}
  • 2 years later...
Posted
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?

Posted
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.

  • 4 years later...
Posted
13 hours ago, diegojmap said:

i could only get the selected total using our exemple code
but i also need to show in another row all the total without selecting itens
how can i do this?

Hello,

If I understood you correctly, perhaps this solution will suit you?

image.png.76998c4dedfa4fb6e7957f373a8928ab.png

Posted

kinda.

Using your Screenshot i want your Total cost and at the same time i want to show the "selected total cost"

but when i use the the function GetSelection() i cant show all the total cost at the same time

So basically i cant combine both solutions at the same time

As you can see on my screenshot i got 1 item selected and its working, but the total cost of both itens aren't showing even without selecting the first item

image.thumb.png.c3ec5da731b65d549798da8919e77a91.png

Posted
16 minutes ago, diegojmap said:

Hey could you help me?

One of the possible solutions at the moment, but keep in mind that we are changing the uniGUI method, and in future versions this solution may not work properly...

Let's test this solution on this demo example:

\FMSoft\Framework\uniGUI\Demos\Desktop\GridSummary
function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    // columns[2] - third column
    columns[2].summaryRenderer = function(value, summaryData, dataIndex, metaData) {
        if (value && typeof value == "object") {
            
            var v = 0,
                sumv = value["_s" + dataIndex],
                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 ("Total Units (selected): " + v + "<br>" + sumv)
        }
        return ""
    }
}

 

function selectionchange(sender, selected, eOpts)
{
    sender.grid.getView().refresh();
}

image.png.71d31c51ca13160eabb4e7cd97a99603.png

Posted

Well, after some testing i got another problem.

while i have just a few itens showing on screen it worked very well. But when i have to scroll down the page and i select an item all the itens just desapear.

I would like to fix it.

I uploaded a video to show what is happening

Posted

I'm sending you the demo I created to debug the problem Im having in my project.

Also a screenshot showing the minor change I did in your code. It was only the amount of itens i wanna show on screen.

I hope it helps you to reproduce the problem.

image3.png.493abf632b24dc986f499d570316880a.png

GridSummary.zip

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...