How can I eliminate the totals row in Slickgrid 3 when grouping data?

I have implemented multi-row grouping with totals in the headers, but I am facing an issue where empty rows are displayed instead of the totals rows. How can I remove these unwanted totals rows from my grid? Thank you!

.cshtml:

  <div id="gridList" class="grid" style="width: 100%; height: 500px"></div>

.js

$(function() {
    var columns = [
    {
        id: "isExcluded",
        name: "Exclude",
        field: "isExcluded" /*, width: 120*/,
        formatter: Slick.Formatters.Checkmark,
        editor: Slick.Editors.Checkbox, sortable: true
    },
    {
        id: "symbol",
        name: "Symbol",
        field: "symbol",
        sortable: true /*, width: 120*/
    },
    {
        id: "price",
        name: "Price",
        field: "price",
        sortable: true
        //, groupTotalsFormatter: sumTotalsFormatter 
    },
    {
        id: "parent_name",
        name: "Parent Name",
        field: "parent_name",
        sortable: true /*, width: 120*/
    },

    {
        id: "description",
        name: "Description",
        field: "description",
        sortable: true,
        width: 120,
        editor: Slick.Editors.Text,
    },
    { id: "cancel_ind", 
      name: "Canceled", 
      field: "cancel_ind", 
      sortable: true, width: 80 }
];

function requiredFieldValidator(value) {
    if (value == null || value == undefined || !value.length) {
        return { valid: false, msg: "This is a required field" };
    } else {
        return { valid: true, msg: null };
    }
};

var options = {
    editable: true,
    enableAddRow: true,
    enableCellNavigation: true,
    asyncEditorLoading: false,
    autoEdit: true,
    enableExpandCollapse: true,
    rowHeight: 25
};

var sortcol = "parent_name";
var sortdir = 1;
var grid;
var data = [];
var groupItemMetadataProviderTrades = new Slick.Data.GroupItemMetadataProvider();
var dataView = new Slick.Data.DataView({ groupItemMetadataProvider: groupItemMetadataProviderTrades });

dataView.onRowCountChanged.subscribe(function (e, args) {
    grid.updateRowCount();
    grid.render();
});

dataView.onRowsChanged.subscribe(function (e, args) {
    grid.invalidateRows(args.rows);
    grid.render();
});

function groupByParentAndSymbol() {
    dataViewTrades.setGrouping([
        {
            getter: "parent_name",
            formatter: function(g) {
                return "Parent:  " + g.value + "  <span style='color:green'>(" + g.count + " items)  Total: " + g.totals.sum.price + "</span>";
            },
            aggregators: [
                new Slick.Data.Aggregators.Sum("price")
            ],
            aggregateCollapsed: true
            ,lazyTotalsCalculation: true
        },
    {
        getter: "symbol",
        formatter: function(g) {
            return "Symbol:  " + g.value + "  <span style='color:green'>(" + g.count + " items)   Total: " + g.totals.sum.price + "</span>";
        },
        aggregators: [
            new Slick.Data.Aggregators.Sum("price")
        ],
        collapsed: true
        ,lazyTotalsCalculation: true
    }]);
};

grid = new Slick.Grid("#gridList", dataView, columns, options);
grid.registerPlugin(groupItemMetadataProviderTrades);
grid.setSelectionModel(new Slick.RowSelectionModel());

..... /*sorting support etc*/

 // use instead of the default formatter <---  removed not used.
 function sumTotalsFormatter(totals, columnDef) {
    var val = totals.sum && totals.sum[columnDef.field];
    //if (val != null) {
    //    return "total: " + ((Math.round(parseFloat(val) * 100) / 100));
    //}
    return "";
 }

// will be called on a button click (I didn't include the code as irrelevant)
var getDataList = function () {
    $.getJSON('/Home/GetData/', function (json) {
        data = json;
        dataView.beginUpdate();
        dataView.setItems(data);
        groupByParentAndSymbol();
        dataView.endUpdate();
        dataView.syncGridSelection(grid, true);
    });
 };

  getDataList();

});

Answer №1

My problem was resolved by including displayTotalsRow: false in the dataview code - total rows are no longer visible.

 let dataView = new Slick.Data.DataView({ groupItemMetadataProvider: groupItemMetadataProviderTrades, displayTotalsRow: false });

Answer №2

If you are looking for a simple solution to your query, just eliminate the aggregators: [...] section. When I say remove, you have two choices - you can either delete whatever is within the array [...], or you could opt to completely erase that object line (thus removing the entire aggregators[...]).

Now, if you require further clarification on how this works... Let's start by providing some definitions so you can grasp it better. An aggregate refers to a collection of items gathered together to form a total quantity. This total could represent a sum of all fields, an average, or any other type of aggregator you define. Essentially, it involves grouping by the chosen column and providing the calculation result for the group. So, how does this function in the context of SlickGrid? You must specify the type of Aggregator you wish to utilize (such as Avg, Sum, etc.) within your

function groupByParentAndSymbol()
. Defining these aggregators will facilitate the calculation process, but remember - unless they are linked to the field, nothing will be visible. Therefore, it is crucial, as demonstrated in the example you came across, to attach/bind the
groupTotalsFormatter: sumTotalsFormatter
to your columns definition, like this:

...var columns = [{id: "cost", ...width: 90, groupTotalsFormatter: sumTotalsFormatter}, ...];

To summarize... Once the Aggregator, such as

new Slick.Data.Aggregators.Sum("cost")
, is defined, the calculation will occur. However, without binding it to the field, the output will not be displayed. Additionally, the aggregateCollapsed (true/false) option determines whether the sub-total (avg, sum, etc.) appears inside or outside the group when collapsed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to calculate large integer powers efficiently in JavaScript using the mod

I'm currently on the lookout for a reliable JavaScript algorithm as I attempted to implement one using node.js : function modpow_3(a,n, module){ var u = BigInt('1'); var e = equals(a, u); if( e) return a; if(equalsZero(a)) return a; if(pair ...

Discover the technique for choosing an element within an IF statement using the keyword (this)

I am currently implementing bootstrap validation in my project. Here is the JavaScript code I am using: My goal is to achieve the following: $("#create-form").submit(function(e) { if ($("input").val() = "") { $(this).addClass("is-invalid"); ...

Can React Router be integrated with Material UI tabs?

I have made some changes to the code of the Tabs component in material ui, <AppBar position="static"> <Tabs variant="fullWidth" value={value} onChange={handleChange} aria-label="nav tabs example" > < ...

Maximize the YouTube video for full screen viewing

Take a look at the code snippet from our page here: <div className={styles.videoPreview}> <iframe src={`${videoData[router.locale]}?autoplay=0`} title="Flytime" ...

Guide: Previewing uploaded images with HTML and jQuery, including file names

Any constructive criticism and alternative methods for accomplishing this task are welcomed. I am currently working on writing jQuery code that will allow users to preview file(s) without reloading the DOM. To achieve this, I have been using .append() to ...

Warning: Javascript prompt for leaving website

I am currently working on an application and I would like to implement a popup that will appear when a link with the class "extlink-modal-trigger" is clicked. This popup will display a quick warning message, similar to how Facebook handles external links, ...

Incorporating a $match query in MongoDB aggregation with lookup

When retrieving data from 2 collections, I aim to establish a connection between the two based on the MongoDB playground. Specifically, while extracting information from the second collection, I seek to filter results by matching a specific tag. This is t ...

Executing multiple AJAX requests with promises in Angular based on an array of values

I have been working on implementing multiple ajax calls in sequence using Angular. Interestingly, everything seems to be working fine when I use $.ajax, but when I switch to using $http for server requests in Angular, things start to go awry. Both methods ...

Issue with AngularJS 2: Main constructor variables cannot be accessed in other component templates

My main component looks like this: import {Component} from 'angular2/core'; import {HeaderComponent} from './header.component'; import {FooterComponent} from './footer.component'; @Component({ selector: 'my-app&apos ...

What is the source of the compiler options in tsconfig.json?

Currently utilizing Typescript in NestJs, I have incorporated various packages. However, the specific package responsible for altering these settings remains unknown to me: "checkJs": false, "skipLibCheck": true Is there a method to ...

Unable to proceed, WISTIA upload frozen at 100% complete

I recently integrated the Wistia API for video uploads. Everything seemed to be working fine as per the Wistia documentation until I encountered an issue. After uploading a video file, the progress bar would reach 100%, but then an error was logged in the ...

Adjusting the label on the Formik toggler

I have successfully implemented a switcher using Formik that changes the label accordingly with a boolean value. However, I now need to make the label reflect a string value instead of just "true/false." For example, I want it to display "Text1/Text2" inst ...

VSCode is experiencing issues with recognizing .env* files for markup purposes and is also failing to recognize .env.local.* files

Current Environment: Utilizing NextJs, React, and VsCode Noticing a problem with syntax highlighting in my VSCODE editor. I have installed the following extensions: ENV DotEnv As per suggestions, I updated my json configuration file as follows: " ...

Trying to fill a modal with data from a text input on a website

The JavaScript I have for a popup in asp.net seems to be returning blank variables from text boxes on the web page. It appears like there might be something missing in my document.getElementById function, either it's not being used correctly or I shou ...

Upon loading the page, include a class to a specific element within an AngularJS ng-repeat function by evaluating the content of a JSON object

I have a group of buttons that are generated from a json object. Whenever a user clicks on a button, it changes color (referred to as the selected color) using the ng-class directive with bootstrap classes. If the same button is clicked again, it reverts b ...

Top solution for maintaining smooth navigation across web pages

As I dive into the world of web development, I find myself intrigued by the idea of reusing navigation and banners across multiple web pages. However, despite my research efforts, I have yet to come across a definitive answer. My objective is simple: The ...

executing an SQL query with mysql-npm on the Amazon Web Services platform

Hey everyone, I'm facing a bit of a challenge that I'm struggling to solve. It's kind of a strange issue :/ I've created a Lambda function to connect to a MySQL DB using the 'mysql' node package. When I run the function from ...

Exploring AngularJS and its ng-repeat directive along with ng-style

I'm having trouble getting ng-style to work properly with ng-repeat. Here is my code snippet: <div style="display:table-row" ng-repeat="row in Data.Communications" id="{{row.Guid}}"> <div style="display:table-cell;"> <img ng ...

Is it possible to merge JavaScript files exclusively using encore?

I am working on a Symfony project with a Twitter Bootstrap template where the assets are hardcoded in Twig. I would like to use Encore to manage assets, but I want it to only combine JavaScript files without compiling them further. Is there a way to confi ...

Assistance in using jQuery to locate specific div elements is

I am currently working on creating a navigation bar that features icons triggering contextual submenus upon hover. The main idea is that hovering over an icon will display a popup menu or tooltip with additional options, while still allowing the icon itsel ...