Tips on resolving issues with cellclickable functionality in Angular with gridster2

VERSION: ^9.3.3

HTML

    <button (click)="toggleEditing()">{ editing ? 'cancel' : 'editing' }</button>
        <button>ADD</button>
        <gridster [options]="options">
            <gridster-item class="px-3 py-2" [item]="item" *ngFor="let item of dashboard">
         </gridster-item>
        </gridster>

TS

    editing = false;
    
    ngOnInit() {
     this.options = {
          gridType: GridType.Fit,
          margin: 0,
          outerMargin: null,
          outerMarginTop: null,
          outerMarginRight: null,
          outerMarginBottom: null,
          outerMarginLeft: null,
          useTransformPositioning: true,
          mobileBreakpoint: 640,
          keepFixedHeightInMobile: false,
          keepFixedWidthInMobile: false,
          scrollSensitivity: 10,
          scrollSpeed: 20,
          enableEmptyCellClick: this.editing,
          enableEmptyCellContextMenu: false,
          enableEmptyCellDrop: false,
          enableEmptyCellDrag: this.editing,
          emptyCellDragCallback: this.emptyCellClick.bind(this),
          enableOccupiedCellDrop: false,
          ignoreMarginInRow: false,
          draggable: {
            enabled: this.editing,
            stop: (event) => { this.setFlrLayout(event); }
          },
          resizable: {
            enabled: this.editing,
            stop: (event) => { this.setFlrLayout(event); }
          },
          swap: true,
          disablePushOnDrag: false,
          disablePushOnResize: false,
          pushDirections: { north: true, east: true, south: true, west: true },
          pushResizeItems: false,
          displayGrid: DisplayGrid.Always,
          disableWindowResize: false,
          disableWarnings: false,
          scrollToNewItems: false,
          itemInitCallback: ((item: GridsterItem, itemComponent: GridsterItemComponentInterface) => {
            window.dispatchEvent(new Event('resize'));  // to reisize respective charts 
          })
        };
    }
     toggleEditing() {
        this.editing = !this.editing;
        }


 

      ngOnChanges() {
     if (this.options && this.editing || this.options && !this.editing) {
          this.options['enableEmptyCellClick'] = this.editing;
        }
    }

     emptyCellClick(event: MouseEvent, item: GridsterItem): void {
    console.log(`test ${item}`);
    }

I am attempting to implement multi-selection in a grid. However, the click functionality is not working as expected. When I click on an empty cell, it does not trigger the console log in the dev tools.

For example, when I click on multiple empty cells for selection and then click "ADD", it should add those selected items accordingly.

https://i.stack.imgur.com/mA5qE.png

TO

https://i.stack.imgur.com/cJtYW.png

Answer №1

Within your TypeScript file, you are setting the value of options. Could you update the enableEmptyCellClick: false to enableEmptyCellClick: true?

Appreciate it @ABC

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

Adding an image to a jQuery class name on the fly

I am attempting to add an image before a div by using its className with jQuery. function insertImage(obj) { var dynamicClass = $(obj).prop("className"); After retrieving the classname, I now encapsulate it in single quotes and add a dot to access t ...

It is not possible to repeatedly hear the same event on a single element

It seems that I am unable to listen to an event multiple times on a single element. Upon investigation, I have found the following observations: This issue arises when triggering an RxJS observable from lifecycle methods such as ngAfterViewChecked, ngDoC ...

What are some ways to incorporate inline TypeScript Annotations into standard JavaScript code?

If you're using VSCode, there's a new feature that allows you to implement type checking for traditional JavaScript files. There are instances where I wish to specify the type of a variable or parameters in a method or function to enhance auto-co ...

"Encountering a 404 error when submitting a contact form in Angular JS

Looking to set up a contact form for sending emails with messages. Currently diving into Angular Express Node Check out the controller code below: 'use strict'; /** * @ngdoc function * @name exampleApp.controller:ContactUsCtrl * @descripti ...

Guide on obtaining the total value from a JSON Array in Angular 2 using TypeScript

I received a JSON response which includes carts values with different amounts. "carts": { "value": [ { "Amt": 40 }, { "Amt": 20.25 }, ...

Ways to troubleshoot and verify values in PHP that are sent through AJAX

In my jQuery function, I am using AJAX to send values to a PHP file: $.ajax({ //make ajax request to cart_process.php url: "cart_process.php", type: "POST", dataType: "json", //expect json value from server data: { quantity: iqty, ...

Implementing an animation feature to facilitate the item filtering process when clicked on

I have recently developed a filter gallery and I am encountering an issue with animating the filter items when clicking on buttons. The problem with my current code is that it only toggles the animation effect rather than smoothly animating each time a but ...

Challenges faced while setting up a fresh Angular 7 project

Encountered an error while trying to create a new project using angular cli. I attempted npm clear cache --force and manually deleted the npm cache folder, but neither solution resolved the issue. No proxy is needed for internet connection Ran command: n ...

Utilizing Azure Function Model v4: Establishing a Connection with Express.js

Using Model v4 in my Azure function index.ts import { app } from "@azure/functions"; import azureFunctionHandler from "azure-aws-serverless-express"; import expressApp from "../../app"; app.http("httpTrigger1", { methods: ["GET"], route: "api/{*segme ...

When clicking to open the md-select on Angular Material 1.1.0, an unwanted [object object] is being appended

Every time I try to open the md-select input, an [object Object] (string) is added to the body tag. Click here to see the md-select input After clicking the md-select once, this is how the body looks ...

Utilize React.useImperativeHandle() for declaring custom types

function App(){ const refEl:React.MutableRefObject<any> = React.useRef(null); // I am uncertain about the appropriate type here. React.useEffect(()=>{ if(refEl.current){ refEl.current.start() } }, []); return <Countdown ref={refEl} ...

Executing a function after an AngularJS directive's reference function has been called

<CustomDirective customValue="someValue" anotherFunctionRef="anotherFunction()"></CustomDirective> angular.module('AppName', ['OtherDependencies']). directive('CustomDirective', ...

Issues with Tagged Union Types in Visual Studio Code

Currently, I am working on implementing a tagged union type pattern for my action creators within a redux application. The TypeScript compiles without any issues, however, my code editor, Visual Studio Code 1.26.1, is flagging an error. [ts] Type &ap ...

Eliminate the classes that were inserted through Jquery

I'm currently working on an accordion and I've encountered an issue with jQuery adding classes that I don't want. How can I prevent jQuery from adding certain classes? The code below is what I have, but for some reason, jQuery keeps adding t ...

What is the best way to apply a mask to a textbox to format the date as MM/yyyy using a mask

In my asp.net application, I have a TextBox for entering Credit card date (month & year only). I tried using the 'TextBox with masked edit extender' and set Mask="99/9999" with Mask Type="Date. However, it is not working as expected - it only wor ...

Leveraging the power of Promise creation

I am facing an issue where I am trying to utilize the getPromise function with various URLs in order to obtain different promises, but encountering undefined values in the success function of the second promise. var http=require('http'); var URL ...

Is there a way to alphabetically and numerically organize a table in vue.js?

Currently, I am implementing sorting functionality for a table using vue.js. While I have successfully achieved ascending sorting for numbers, I am facing challenges with getting the descending and alphabetical sorting to function properly. Below is the H ...

React | Utilizing ForwardedRefs with React Components

I'm currently working on a React project where I am creating a custom component that needs to be exported using forwardedRef. However, as I attempt to do this, an error keeps popping up: error This is the code snippet causing the issue: export inter ...

filtering an array based on a specific property will result in the original array remaining

Working on filtering an array of objects based on a certain property using the following code snippet: if (payment == Payment.CREDIT_CARD) { this.currenies.filter((currency: Currency) => currency.isFromEurope === true); console.log(this.currencies) ...

Angular websocket failing to execute API post request

I am currently developing a demo application that involves making a POST API call. The main goal is to send a query via the POST API call and receive data from the API as a response. One key feature of this API is that it provides updated data every minute ...