[CLOSED] CustomSummaryType in DateColumn

  1. #1

    [CLOSED] CustomSummaryType in DateColumn

    Hi,

    we want to use the Property .CustomSummaryType = "totalDateTime" in DateColumn.
    If there is no date in this row(ColumnIndex), i don't want to count this row.

    Is it possible to send the ColumnIndex to this function totalDateTime?

    For example if (record.get(ColumnIndex) <> '') total += 1;

    I hope you understand me :-).

    Thanks
    Gidi





    Dim _ScriptTotalDateTime As String = "<script>"
    
                    _ScriptTotalDateTime &= " var totalDateTime = function (records) {"
                    _ScriptTotalDateTime &= " var i = 0,"
                    _ScriptTotalDateTime &= " length = records.length, "
                    _ScriptTotalDateTime &= " total = 0,"
                    _ScriptTotalDateTime &= " record;"
    
                    _ScriptTotalDateTime &= " for (; i < length; ++i) {"
                    _ScriptTotalDateTime &= " record = records[i];"
                    _ScriptTotalDateTime &= " total += 1;"
                    _ScriptTotalDateTime &= " }"
                    _ScriptTotalDateTime &= " return total;"
                    _ScriptTotalDateTime &= " };"
                    _ScriptTotalDateTime &= "</script>"
    
    aktPage.ClientScript.RegisterClientScriptBlock(aktPage.GetType(), "totalDateTime", _ScriptTotalDateTime)
    Last edited by fabricio.murta; Feb 22, 2021 at 6:48 PM.
  2. #2
    Hello @gidi!

    Sorry for the long delay taken to respond your inquiry, but it is not really clear to me what you need here.

    If the calculation of the summary is done by that composed script snippet you posted, all you need to do is, before the script code concatenated at line 10, check if the date field in that record has a value. Something like this:

    _ScriptTotalDateTime &= " if (record.MyDateColumnDataIndex == <value_that_represents_an_empty_date>) continue;"
    So total is not incremented when the stepped record has the empty data.

    Notice:

    - MyDatecolumnDataIndex should refer to the DataIndex in the DateColumn you are considering and, depending on the context, assuming your date column's DataIndex is DateValue, it should be called as record.get('DateValue') to safely access the record's field.

    - <value_that_represents_an_empty_date> refers to whatever you get in your data when you consider "there is no date in this row", e.g. undefined, null, or an empty string "", etc.

    Hope this helps, if not, please provide a full simplified test case so we can reproduce and tell you how exactly to attain that result.

    If in doubt about how to come up with a test case we can use, please refer to these guideline threads:

    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi,

    thanks for your Reply. I create then ColumnModel dynamicly. So i want to use the CustomSummaryType Property to manipulate the Summary.

    
     For Each nCol As DataColumn In TFStore.DataTable.Columns
    
               Select Case nCol.DataType.Name.ToString.ToLower
    
    
                       Case "datetime"
                                Dim nGridCol As New DateColumn
                                With nGridCol
                                            .DataIndex = nCol.ColumnName
    
                                            .CustomSummaryType = "totalDateTime"  
                                End with
               End Select
    Next
    Now i want to transfer the Variable nCol.ColumnName into the Javascript Function like

    
    
     For Each nCol As DataColumn In TFStore.DataTable.Columns
    
               Select Case nCol.DataType.Name.ToString.ToLower
    
    
                       Case "datetime"
                                Dim nGridCol As New DateColumn
                                With nGridCol
                                            .DataIndex = nCol.ColumnName
    
                                            .CustomSummaryType = "totalDateTime(" & nCol.ColumnName & "," & nMultiplier & ")" 
                                End with
               End Select
    Next
    I need this function ...

    
    
     var totalDateTime = function (records, ColumnName, Multiplier) {
     var i = 0,
     length = records.length, 
     total = 0,
     record;
    
     for (; i < length; ++i) {
        record = records[i];
    
        if (record.get(ColumnName) != '')
        {
            total += 1;
        }
     }
     return total * Multiplier;
    }
    Sorry for my bad english...

    Grüße
    Gidi
  4. #4
    Hello again, Gidi!

    It looks like in your second code block, line 12, you are building something like:

    totalDateTime(myColumnNameHere, myMultiplierIntegerHere)

    Whereas in your third code block, which seems to be javascript, you have the function signature as:

    var totalDateTime = function (records, ColumnName, Multiplier) {

    Besides, the customSummary setting only accepts a function name/reference, you can't add arbitrary code as you are trying.

    The summary handler has no knowledge of the current column it is processing, you need to hardcode in the method the column name you are computing the summary of.

    This settings is, though, deprecated in Ext JS for some time now, so it would be a good idea to use the current SummaryRenderer setting.

    As you can see, all our examples involving SummaryType rely in hardcoding the column name in the custom summary method:
    - GridPanel > Locking_Grid > GroupingSummary
    - GridPanel > Locking_Grid > GroupingSummary_with_group_headers
    - GridPanel > Miscellaneous > Grouping_TotalRow
    - GridPanel > Plugins > GroupingSummary
    - GridPanel > Plugins > Summary

    If you do use SummaryRenderer though, you'll get an amicable function(value, summary, dataIndex, gridCell) to play with, and return whatever summed value you want for the current column.

    It should be something like this in your javascript code:

    var totalDateTime = function (value, summary, dataIndex) {
        var column = this,
            grid = column.gridRef,
            store = grid.getStore(),
            records = store.getRecordsValues(),
            computed_total = 0;
    
        Ext.each(records, function (record) {
            if (!Ext.isEmpty(record[dataIndex])) {
                computed_total++;
            }
        });
        return computed_total * column.multiplier;
    }
    As you can see, I didn't need to hardcode any string in the above method, so this probably is what you're looking for.

    As for the multiplier, you can set this as a parameter tied to the column, say, adding a custom config to the column with that multiplier, like this:

    Dim nGridCol As New DateColumn
    With nGridCol
        .CustomConfig.Add(New ConfigItem("multiplier", nMultiplier.ToString(), ParameterMode.Raw))
        .SummaryRenderer.Fn = "totalDateTime"
    And that's how Multiplier was available without being hardcoded in the javascript code suggested.

    Bear in mind this is just suggestions given the context you provided, we can't provide a pin-pointed answer unless a we are able to reproduce the scenario you are facing.

    The same exmaples linked above do use SummaryRenderer but none of them highlight using this custom function approach, so we couldn't really test whether the code provided above is 100% correct especially given the constraints you have.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Thank You!!! Thats Great!

    But "store = grid.getStore()," there is a Problem. I can use "store = Ext.getCmp('GridPanel').getStore()" thats OK

    If i want a to use more then 1 Parameter, there is a new Problem.

    .CustomConfig.Add(New ConfigItem("multiplier", nMultiplier.toString(), ParameterMode.Raw))
    .CustomConfig.Add(New ConfigItem("GridName", GridName.toString() , ParameterMode.Raw))

    what can i do?

    I would like to invite you to a beer. Whats your Paypal address?

    Grüße
    Micha
  6. #6
    Hello, Micha!

    Just in case, you can have one forum account per developer here, up to the number of developers your company is licensed for, to be added to the premium group. Just email us at support@ext.net and request the accounts, so you can all make posts from your specific accounts if you prefer.

    Quote Originally Posted by gidi
    But "store = grid.getStore()," there is a Problem. I can use "store = Ext.getCmp('GridPanel').getStore()" thats OK
    Yes, I had to figure out some random example and usually the code provided won't match 100%, that's why we insist so on code samples. Makes answers simpler to understand and helps us provide the best response to issues.

    Quote Originally Posted by gidi
    If i want a to use more then 1 Parameter, there is a new Problem.

    .CustomConfig.Add(New ConfigItem("multiplier", nMultiplier.toString(), ParameterMode.Raw))
    .CustomConfig.Add(New ConfigItem("GridName", GridName.toString() , ParameterMode.Raw))
    what can i do?
    This looks like something that should work. You are just appending ConfigItem instances to the List of CustomConfig. The syntax looks correct. I tell you what you can do: can you make a test case we can run on our side to reproduce the scenario you have? I believe just a simple grid panel with some dummy mock data should do, but I can't figure how we'd do it ourselves as we may just miss essential part that's needed to reproduce the behaviour you are getting.

    But... here goes nothing:

    In the first, you are sending nMultiplier.toString() as ParameterMode.Raw. In JavaScript side, it will translate into 2, or 8, which is a constant value (as with, say, var x = 8;).

    Your second you are sending a GridName.toString() and also ParameterMode.Raw. A grid name being a string would be strange to have in javascript something like var x = MyGridName;, we'd need to have a variable named after this defined beforehand... but instead, you probably want to var x = "MyGridName";, with quotes for a string constant, right?

    If that's the case, you can just drop the ParameterMode.Raw from the second line and voila:

    .CustomConfig.Add(New ConfigItem("GridName", GridName.toString()))
    Internally, you are building a JavaScript object. Ext.NET generally does a good job on guessing what it should do, but with ParameterMode.Raw we really wanted to tell it not to fiddle with the value (for the intended setting was supposed to hold an integer not a string). So in practice, you will see something output like that on the generated code:

    { 
        (...)
        multiplier: 8,
        gridName: MyGridName,
        (...)
    }
    You can open developer tools on your browser and search for these strings in the Ext.NET "init script" response (in "sources tab", usually the first resource attached to the web page).

    You want instead:

    { 
        (...)
        multiplier: 8,
        gridName: "MyGridName",
        (...)
    }
    Besides, this looks to me as duplicated information you are storing. You are creating a property in the columns indicating the grid name you would also need to look up in the list of all components before you can access it, while a column is always assigned to a single grid, and it should be "directly addressable" via that gridRef property. So maybe it'd prove worth putting a little more thought on that matter, and simplify your code behind a bit gaining a little precious performance on the front end.

    I'm not sure this helps, it's a lot of text and uncertainty, so please don't take all I said above for granted, I'm pretty much in the dark here.

    Quote Originally Posted by gidi
    I would like to invite you to a beer. Whats your Paypal address?
    Thanks for your kind invite and sign of appreciation of the support, I'm glad we could get thru this with a positive feeling from you. :)

    We are doing our best to keep low during the pandemics so we'd have to pass the beer for now. But thanks for the kind words!
    Fabrício Murta
    Developer & Support Expert
  7. #7
    Hi fabricio,

    thanks for your help.

    No, i'm one person :-). My friends call me gidi (Gideon, my last name) or micha, my family michi ;-).

    Now I'm understand the ParameterMode.Raw. I use the ParameterMode.Value. It's Ok.

    Now the the Script looks like


                    var totalDateTime = function (value, summary, dataIndex) {
                    var column = this,
                    store = column.gridRef.getStore(), 
                    records = store.getRecordsValues(),
                    totalCount = 0,
                    aktCount = 0;
    
                    Ext.each(records, function (record) {
                         if (!Ext.isEmpty(record[dataIndex])) { 
                               totalCount++;
                               aktCount++;
                         }else{
                               totalCount++;
                         };
                    });
                    return aktCount + ' / ' + totalCount +'<br/>' + Math.round(((aktCount * 100) / totalCount)) + '%';
                    };
    But this is wokrs very slowly. My Example has over 1000 rows und 35 Columns who use the Script.

    Do you have any idea?

    The multiplier etc. i use in some other Script. It works fine.

    Thanks
    Gidi
  8. #8
    Hello again, Gidi!

    Quote Originally Posted by gidi
    No, i'm one person :-). My friends call me gidi (Gideon, my last name) or micha, my family michi ;-).
    Ok, don't worry, it was just in case there were multiple people on the same account -and- you did that thinking you couldn't have individual accounts. :)

    Quote Originally Posted by gidi
    But this is wokrs very slowly. My Example has over 1000 rows und 35 Columns who use the Script.

    Do you have any idea?
    Nothing specific but, for just 1,000 records I am sure you can optimize it to get under-a-second response, but that's something beyond our reach as Ext.NET framework support. In general terms you should reduce redundant code, optimize loops (merge different loops when a single can do what both does), and avoid deviations (ifs) whenever possible.

    For example, if you are calculating the summary for various columns, maybe you can make only one summary function, set the summary to only one column, but compute it for the different columns involved and store the results in the summary variable. I believe it stores summary for the various columns in the grid. Nevertheless, it would require deeper knowledge of how summary works in Ext JS; we are talking about optimization now.

    Another approach in case you don't use local (client-side) filters, is using remote summary. So you calculate the summary in the server and deliver it tied to the grid data. Then no calculation is done client-side at all. Lightning fast. Se an example with grouping summary:

    - Grid Panel > Plugins > Remote Group Summary. I believe everything expressed in C# can be done in VB.NET so you should be covered.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  9. #9
    Thank you!!!

    I think the remote Version would be th best. I will try it.

    Greetings to Brazil from Germany.

    Grüße
    Gidi
  10. #10
    Hello again, Gidi!

    Thanks for the feedback, and let us know in case you run into issues implementing that!

    EDIT: I will mark this thread as 'closed' assuming the main issue you had is settled. Let us know otherwise.

Similar Threads

  1. [CLOSED] Help needed with GridPanel CustomSummaryType records.length value
    By TransBIRptSup in forum 4.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 24, 2018, 3:47 PM
  2. [CLOSED] Background Color in CustomSummaryType
    By Z in forum 3.x Legacy Premium Help
    Replies: 10
    Last Post: Apr 26, 2016, 2:08 AM
  3. [CLOSED] CustomSummaryType in grid - regroup in JS
    By Z in forum 3.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 07, 2016, 12:36 PM
  4. [CLOSED] CustomSummaryType and ColumnName
    By bbros in forum 3.x Legacy Premium Help
    Replies: 9
    Last Post: Aug 18, 2015, 3:18 PM
  5. Replies: 3
    Last Post: Nov 19, 2014, 5:30 AM

Posting Permissions