npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fdhoff-ag-grid-autocomplete-editor

v0.0.0-development

Published

Quick implementation of autocompletion into ag-Grid cell using autocompleter package.

Downloads

9

Readme

ag-grid-autocomplete-editor

npm version CD codecov

Quick implementation of autocompletion into ag-Grid cell using autocompleter package.

Install

npm install --save ag-grid-autocomplete-editor

Description

The goal of this package is to provide an easy way to have autocompleted cellEditor into ag-Grid.

Demo

aAwS0747n5

Usage

This package provide a new cellEditor named: AutocompleteSelectCellEditor. You can configure and customize the cell and behavior with the following cellEditorParams:

  • selectData: is a list of data matching the type {value: string, label: string, group?: string}. Or a function type: ((params: IAutocompleteSelectCellEditorParams) => Array<DataFormat>). If no other parameters provided the autcompletion will use this data with a simple .filter. Basically, if you already have local data, you probably don't need anything else.
  • placeholder: the placeholder is a string who will be put onto the input field.
  • required: (boolean = false) To know if editor should cancel change if the value is undefined (no selection made).
  • autocomplete: please see autocompleter for more details about the following parameters
    • render: (same as classical autocompleter) function, except that it take the current cellEditor as first parameter.
    • renderGroup: (same as classical autocompleter) function, except that it take the current cellEditor as first parameter.
    • className: (same as classical autocompleter) default 'ag-cell-editor-autocomplete'
    • minLength: (same as classical autocompleter) default 1. User has to edit the input to trigger data fetch. Which means if minLength = 0 and used with fetch, user has to delete input value to be able to show the list. If you just want to show list on focus without any editing action, use showOnFocus instead.
    • showOnFocus: (same as classical autocompleter) default false trigger first fetch call when input is focused
    • emptyMsg: (same as classical autocompleter) default 'None'
    • strict: ( decide if the user can put free text or not) default true.
    • autoselectfirst: (decide the default behavior of the select (if the first row must be automatically selected or not)): default true
    • onFreeTextSelect: (function called only if the selected text does not exist on the actual select options. Must be use with strict=false): optional Must be use with strict=false.
    • onSelect: (same as classical autocompleter) function, except that it take the current cellEditor as first parameter.
    • fetch: (same as classical autocompleter) function, except that it take the current cellEditor as first parameter.
    • debounceWaitMs: (same as classical autocompleter) default 200
    • customize: (same as classical autocompleter) function, except that it take the current cellEditor as first parameter.
  • ... all the classical arguments taken by a ag-Grid cellEditor.

Example

Simple autocompletion from datasource

import {AutocompleteSelectCellEditor} from 'ag-grid-autocomplete-editor';
import 'ag-grid-autocomplete-editor/dist/main.css';
...
{
   headerName: "Already present data selector",
   field: "data",
   cellEditor: AutocompleteSelectCellEditor,
   cellEditorParams: {
       selectData: [
           { label: 'Canada', value: 'CA', group: 'North America' },
           { label: 'United States', value: 'US', group: 'North America' },
           { label: 'Uzbekistan', value: 'UZ', group: 'Asia' },
       ],
       placeholder: 'Select an option',
   },
   valueFormatter: (params) => {
       if (params.value) {
           return params.value.label || params.value.value || params.value;
       }
       return "";
   },
   editable: true,
}

Autocompletion with Ajax request

import {AutocompleteSelectCellEditor} from 'ag-grid-autocomplete-editor';
import 'ag-grid-autocomplete-editor/dist/main.css';
...
{
   headerName: "Autocomplete with API Country based",
   field: "data",
   cellEditor: AutocompleteSelectCellEditor,
   cellEditorParams: {
       autocomplete: {
           fetch: (cellEditor, text, update) => {
                   let match = text.toLowerCase() || cellEditor.eInput.value.toLowerCase();
                   let xmlHttp = new XMLHttpRequest();
                   xmlHttp.onreadystatechange = () => {
                       if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
                           let data = JSON.parse(xmlHttp.responseText);
                           let items = data.map(d => ({ value: d.numericCode, label: d.name, group: d.region }));
                           update(items);
                       }
                       if (xmlHttp.status === 404) {
                           update(false);
                       }
                   };
                   xmlHttp.open("GET", `https://restcountries.eu/rest/v2/name/${match}`, true);
                   xmlHttp.send(null);
           },
       }
       placeholder: 'Select a Country',
   },
   valueFormatter: (params) => {
       if (params.value) {
           return params.value.label || params.value.value || params.value;
       }
       return "";
   },
   editable: true,
}

Simple autocompletion who allow user to enter any text

import {AutocompleteSelectCellEditor} from 'ag-grid-autocomplete-editor';
import 'ag-grid-autocomplete-editor/dist/main.css';
...
{
   headerName: "Already present data selector",
   field: "data",
   cellEditor: AutocompleteSelectCellEditor,
   cellEditorParams: {
       selectData: [
           { label: 'Canada', value: 'CA', group: 'North America' },
           { label: 'United States', value: 'US', group: 'North America' },
           { label: 'Uzbekistan', value: 'UZ', group: 'Asia' },
       ],
       placeholder: 'Select an option',
       autocomplete: {
           strict: false,
           autoselectfirst: false,
       }
   },
   valueFormatter: (params) => {
       if (params.value) {
           return params.value.label || params.value.value || params.value;
       }
       return "";
   },
   editable: true,
}

Dependencies

Thank's to

  • Thank's to ag-grid-auto-complete who was aiming AngularJS and was inspirational source for this package.
  • Thank's to autocompleter for the easy and really customizable autocompletion logic.
  • Thank's to ag-Grid for the great ag-Grid package.

LICENSE

This project is onto MIT license see LICENSE file.