"Enhance your Handsontable experience with customizable dropdowns allowing for multiple

Seeking to enhance the functionality of the handsontable plugin by enabling multiple selections in its dropdown list. Tried extending the base Editor within the library following suggestions from this resource. Spent considerable time examining the source code without much success.

Open to solutions utilizing Angular extension or native ECMA5 or 6 methods for extending the plugin.

Considered extending the framework with the provided code snippets focusing on 'multiselect' and 'Handsontable.MultiselectDropdownCell'. Implemented a modified version of the dropdown editor, but still struggling to pinpoint key areas.

 // Code snippet here...

Encountering difficulty tracing the click event when users select items in the dropdown menu. Debugging processes hindered by the Traceur tool. Attempts to capture click events within the module proved unsuccessful. Need assistance identifying where to modify code for supporting multiple selections.

Fiddle: http://jsfiddle.net/tjrygch6/

Any help would be greatly appreciated. Thank you!

Answer №1

Glad I could assist you. It took some time for me to go through the API and customize the code :)

I utilized sample code from the latest version of the Handsontable library and made a few tweaks.

There may be some bugs present since this is just a prototype, so feel free to edit and enhance it further.

Unfortunately, I couldn't get the dropdownlist to be clickable. It appears to be related to z-index or other CSS properties. I trust that you will be able to figure out how to fix it. For now, you can use the keyboard to select items by holding shift for multiple selections.

The output consists of the selected options joined together with commas.

For example:

https://i.sstatic.net/k70dC.png https://i.sstatic.net/23ftW.png

To enable this functionality, add the following code after loading the Handsontable library. This will extend the cell types in your Handsontable.

(function(Handsontable) {
    var SelectEditor = Handsontable.editors.BaseEditor.prototype.extend();

    // Implement necessary methods
})(Handsontable);

To implement this, follow these steps:

var container = document.getElementById("example1");
var hot1;

hot1 = new Handsontable(container, {
    data: [
        ['2008', 'Nissan', 11],
        ['2009', 'Honda', 11],
        ['2010', 'Kia', 15]
    ],
    colHeaders: true,
    contextMenu: false,
    columns: [{}, {
        editor: 'select',
        selectOptions: ['Kia', 'Nissan', 'Toyota', 'Honda'],
        multiple: true
    } {}]
});

View a live demo here

If you wish to make changes later on, consider modifying the prepare and init methods accordingly. These methods handle configurations and rendering of the editor.

In terms of where things are located in the code, Handsontable separates cell types into editors and renders. You'll find the HTML code of the editor within the init method, while the getValue method contains the value displayed in the cell when not in edit mode.

I hope this explanation proves helpful and aligns well with your existing setup.

Answer №2

Impressive dedication put into this. Fast forward over a year later, and the process has become much smoother.

My successful experience using the Chosen jQuery plugin made things quite straightforward.

Check out someone's example: https://github.com/mydea/handsontable-chosen-editor

The elegance of Chosen shines through with its utilization in autocomplete alongside multiselect features. Below is the custom renderer used:

function customDropdownRenderer(instance, td, row, col, prop, value, cellProperties) {

    var selectedId;
    var optionsList = cellProperties.chosenOptions.data;

    if(typeof optionsList === "undefined" || typeof optionsList.length === "undefined" || !optionsList.length) {
        Handsontable.TextCell.renderer(instance, td, row, col, prop, value, cellProperties);
        return td;
    }

    var values = (value + "").split(",");
    value = [];
    for (var index = 0; index < optionsList.length; index++) {

        if (values.indexOf(optionsList[index].id + "") > -1) {
            selectedId = optionsList[index].id;
            value.push(optionsList[index].label);
        }
    }
    value = value.join(", ");

    Handsontable.TextCell.renderer(instance, td, row, col, prop, value, cellProperties);
    return td;
}

Followed by the setup of a specific column as shown below:

columns: [
    {},
    {},
    {type: 'numeric'},
    {type: 'dropdown', source: ['', 'NAME', 'FNB']},
    {},
    {},
    {},
    {},
    {},
    {},
    {},
    {type: 'dropdown', source: ['', 'S', 'M']},
    {},
    {},
    {
        renderer: customDropdownRenderer,
        editor: "chosen",
        width: 150,
        chosenOptions: {
            multiple: true,
            data: productData
        }
    },
    {},
    {editor: false, readOnly: true, width: 1}, 
    {editor: false, readOnly: true, width: 1}
],

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

Exploring the world of JSON files using JavaScript

Basically, my bot responds to a command (!accounts) by providing users with information based on their ID. For example, if an ID of 662 sends the command !account, the bot will search for steamID 662 in the json files and display the currency and correspon ...

What is the best way to determine the click position on a square-shaped element?

Is there a way to retrieve the precise position of a square element when it is clicked on? ...

Open the JSON file and showcase its contents using Angular

I am attempting to read a JSON file and populate a table with the values. I've experimented with this.http.get('./data/file.json') .map(response => response.json()) .subscribe(result => this.results =result, function(error) ...

Is there a way to transform a string property into a custom type in a TypeScript array?

I am faced with a situation where I have an interface that is extending a MongoDB document, along with some sample data that is also extending that interface. Below is an outline of the interface: export default interface IModel extends Document { _id: Obj ...

Does DraftJS prompt content change when focused?

There is an editor on a page with a 'save' button. The goal is to only display the 'save' button if there are changes since the last save. When saving, this.setState({hasChanges: false}) is set and in the onChange function, hasChanges i ...

Is there a way to convert various elements sharing the same class into a list of array items?

Essentially, I am dealing with multiple elements sharing the same class name. My goal is to retrieve an array of integers from an API and then iterate through each element with this class name, replacing them with elements from the array sequentially. For ...

The export "hasInjectionContext" is not provided by the source file "node_modules/vue-demi/lib/index.mjs", but it is being requested in the file "node_modules/pinia/dist/pinia.mjs"

Every time I launch my program, the console displays an error message stating that "hasInjectionContext" is not exported by "node_modules/vue-demi/lib/index.mjs", imported by "node_modules/pinia/dist/pinia.mjs" at line 6:9. I ...

Initiate a series of tasks and await their completion using RxJS / Redux Observables

My app requires an initialisation action to be fired, followed by a series of other actions before triggering another action. I found a similar question on Stack Overflow However, when attempting this approach, only the initial APP_INIT action is executed ...

What is the best method to determine the mean score by utilizing the ID values obtained from API responses?

These are the responses retrieved from the API: const attractions = [ {"id": 1,"name": "drive on avenue"}, {"id": 2, "name": "diving"}, {"id": 3,"name": "visiting ma ...

Unraveling the onsubmit FormObject in an HTML form within the Google Sheets Sidebar: Tips and tricks

In the sidebar, I am setting up a form with 27 inputs to create new sheets based on various criteria. The form includes a text entry field and multiple groups of radio buttons and checkboxes. However, I am currently facing an issue when trying to create a ...

Interactive map navigation feature using React.js

Can someone help me figure out how to create a dynamic map with directions/routes? I am currently using the Directions Renderer plugin, but it only shows a static example. I want to generate a route based on user input. Below is the code snippet: /* ...

Disabling click events on a span tag in Angular 6: A step-by-step guide

Is there a way to disable the click event for deleting hours with the 'X' symbol based on a condition? Thank you in advance. <table navigatable class="<some_class>"> <tbody> <tr *ngFor="let item of ...

Creating a stylish look for a selection of multiple menu options

option:active { color: red; } option:focus { color: green; background: green; } option:checked { color: yellow; background: yellow; } <select multiple> <option>One</option> <option>Two</option> <option&g ...

Utilizing Javascript / jQuery to eliminate specific CSS styles

I am facing an issue with the CSS code for a table positioned at the bottom of the screen. The current code includes a filter specifically for IE 8, but I need to make it compatible with IE 10 as well by removing the filter and adding a background color. ...

Issue with ng-click not triggering the $mdDialog callback

Utilizing Angular Material, I have functionality in TasksCtrl that triggers a $mdDialog - utilizing the locals property to pass an object that will be changed in DialogCtrl before being returned to the view. Nevertheless, the .then() callbacks do not trig ...

I want to utilize the "new" operator in JavaScript across multiple JavaScript files based on the class I need to implement

I currently have multiple JavaScript files containing jQuery code. Each file is included in my JavaServerPages as needed. I am seeking a way to create a common object or class in JavaScript that can be utilized across other JavaScript files. One approach ...

What could be causing my supposedly correct-looking JSON to be invalid?

I've been trying to figure this out for a while now, but I just can't seem to understand why my JSON keeps showing as invalid... When I run it through JSONLint, I get the following error Error: Parse error on line 107: ...pair?", "answ ...

Get the coordinates needed for a Google Map display

I need help with this information: 45°25'02.98" 10°11'30.39", does anyone know how to extract the Latitude and Longitude for use in gLatLng? ...

How can I resolve the issue of not returning anything ondrop in my code?

Whenever I drop my div containing an image, I don't see anything. And when I try to access its ID, I get a null value. How can I extract information from a div with an image and append a row with it? For code samples or to check the codepen example, v ...

Delayed Passport Session Login

Every time I try to log in, my Express app loads very slowly... I've implemented Passport and Express Validator, but there are no errors. However, the login process for some users is extremely slow. Can anyone offer assistance? Below is a snippet o ...