Git Product home page Git Product logo

ag-grid-autocomplete-editor's Introduction

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.

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.

ag-grid-autocomplete-editor's People

Contributors

avallete avatar dependabot[bot] avatar mrbilly222 avatar rrajewski avatar ying-zhou-git avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ag-grid-autocomplete-editor's Issues

[BUG] Cannot read property PopupComponent

  1. I'm loading ag-grid-autocomplete-editor with document.createElement('script') (src= .....ag-grid-autocomplete-editor.js) instead of "import {AutocompleteSelectCellEditor} from 'ag-grid-autocomplete-editor';"
  2. I use the enterprise version of ag-grid (and have edited require("ag-grid-community") to require("ag-grid-enterprise"))
  3. I get this error in the javascript console:

Uncaught TypeError: Cannot read property 'PopupComponent' of undefined
at Object.220 (ag-grid-autocomplete-editor.js:1)

Setup End-to-End and Unit Testing

I want to give this project a better stability.

Currently working on setting up e2e and unit-testing of the components using cypress

Here my roadmap for this:

  1. I will start small by doing end-to-end testing of the 'autocompleter' lib (the one responsible for the actual select behavior).
  2. Then, will move on unit and e2e testing of the actual ag-Grid editor.
  3. And at last, I may refactor the 'autocompleter' package, to be able to unit-test it more easily, and leverage the e2e testing to be sure the behavior doesn't change during refactoring.

The actual WIP branch is: https://github.com/avallete/ag-grid-autocomplete-editor/tree/unit-test-project-setup

CI travis can be found here: https://travis-ci.org/avallete/ag-grid-autocomplete-editor
Cypress Dashboard related to CI build are here: https://dashboard.cypress.io/#/projects/eqz3n2/runs

To setup, run and develop new tests locally, here is the procedure:

git clone [email protected]:avallete/ag-grid-autocomplete-editor.git
cd ag-grid-autocomplete-editor && git checkout unit-test-project-setup
cd tests && npm install && npm run start

Modify the webpack.prod.js file to remove eval() from production bundles

Hi, we're experiencing a CSP issue with this package due to the use of eval for sourcemaps in the production bundle, is it possible to remove the use of eval for the production bundles, or perhaps introduce a third bundle that is for use in production without sourcemaps.

Happy to produce a PR the third option or remove it from the production bundle entirely, but thought I'd check with you as to what you'd prefer.

There's some information on how to do this in the ticket below if interested
webpack/webpack#6461

version requirement? angular/ag-grid

Hi,

I am using this editor with angular v5.x and ag-grid v22.x.
When I type in the text input, I do not see options as drop down but if I enter the value that is in the selectedData array, it accepts and shows the value.
Is there any version requirement for my case specifically to get the autocompleter to show matching values?

Thanks
H.

Open the list as soon as you enter the edit mode

Hi, there is way to open the list as soon as you enter the edit mode?

In some cases the user doesn't know the possible values, and if the values list is not huge, I think it's better to show the full list so it can see all the options he can choose.

There's some way to accomplish this?

Note: I research the autocomplete library but it seems that it will require a fix with yours
denis-taran/autocomplete#20

Thanks for all!

conditionally render in cell editor is not working with ag-grid autocomplete

conditionally render in cell editor is not working with ag-grid autocomplete
In the below example I am using two types of cell editor select & normal text editor.
Select editor is rendered when (params.data.contextValueTypeName === "Select") else normal text editor is rendered.
But when I am using AutocompleteSelectCellEditor in place of select editor it is giving some error.

columnDefs: [
        {
          headerName: "Value",
          field: "valueField",
          editable: true,
          cellEditorSelector: params => {
            if (params.data.contextValueTypeName === "Select") {
              return {
                component: "agRichSelectCellEditor",
                params: {
                  values: params.data.listItems
                }
              };
            }
            return null;
          }
]

autocomplete

If the autocomplete suggestions box can't fit to bottom it jumps to top of the page

This is example from the demo in https://stackblitz.com/edit/ag-grid-autocomplete-editor:

If the autocomplete box can't fit to the bottom it jumps to fixed top. This can be tested in the example. First image the autocomplete options looks normal but second in the second image I resize the window so it won't fit and it jumps to top. In the example it's not too bad but when the autocomplete is positioned in a full height page at the bottom the autocomplete options jump to the top of the page.

example_cant_fit2

example_cant_fit1

Cells not in focus after selection on autocomplete cells

Using the demo given, under the "Ajax country request" column.

When you type 'cana' and hit Tab key, it'll select 'Canada' and move over the right, which is the 'Capital slow request with spinner' column.

However, it is not in focus anymore and it doesn't take any input from the keyboard until you give it a mouse click.

The default behavior is that it should be editable.

Take 'Price' column for example, after you enter a value and hit Tab key, you will be able to enter 'cana'

support for ag-grid 25 and typescript

There seem to be some typescript issues with AutoCompleteSellectCellEditor - property gridOptionsWrapper is private but not in type PopupComponent which it extends

ERROR in C:\dev\ag-grid-autocomplete-editor\ag-grid-autocomplete-editor.ts
./ag-grid-autocomplete-editor.ts
[tsl] ERROR in C:\dev\ag-grid-autocomplete-editor\ag-grid-autocomplete-editor.ts(76,46)
      TS2416: Property 'gridOptionsWrapper' in type 'AutocompleteSelectCellEditor' is not assignable to the same property in base type 'PopupComponent'.
  Type 'GridOptionsWrapper | undefined' is not assignable to type 'GridOptionsWrapper'.
    Type 'undefined' is not assignable to type 'GridOptionsWrapper'.

Setup semantic-release into CI

Would be nice to have semantic-release setup with automatic version bumping and npm publishing into the CI.

Will avoid manual publishing when merging PR (like in #68)

CellEditingStopped in fullRow Edit Mode

I am editing a row in ag-grid with editType=fullrow. This works fine for the cell editors that are packaged with ag-grid but I am having a problem with the AutoComplete editor.

When I click on a selection then the cellEditingStopped and rowEditingStopped functions are called. The result is that my row is submitted before I am ready and the other rows have been completed,

I'm quiet new to Angular and Ag-Grid so I am not sure if this is a bug or my misunderstanding of how it should work.

Thanks

Missing files in latest release

Getting this error when i try running my app with the latest version:

ERROR in node_modules/ag-grid-autocomplete-editor/ag-grid-autocomplete-editor.d.ts:3:48 - error TS2307: Cannot find module './autocompleter/autocomplete' or its corresponding type declarations.

3 import { AutocompleteItem, EventTrigger } from './autocompleter/autocomplete';

If I grab the autocompleter folder from v1.4.0 and copy it to the folder it works, but it seems like that folder isn't being included anymore.

Thanks for the great package, and sorry if it's just me doing something weird!

Error with regexish value rendering

Escape regex characters in the value passed into in the render function. Previously failed in my case when the value had a single parenthesis in the string.

CellEditor width

Thank you for your excelent component, really great time saving for us!!
Is there any option to set the width of the editor. My ColumnDef has it's own width as per ag-grid documentation like this:
... headerName: 'Part', field: 'part.name', width: '200', cellEditor: AutocompleteSelectCellEditor, ...
But editor itself is much shorter.
image
It would be really useful.
Thank you again!!

[BUG] Memory leak

Hi Andrew,

When I use this component with big data, the program slows down due to memory leaks

Memory Leak

¿Accept promises in selectData?

It would be great allow put promises in selectData. So you can use cellEditorParams to provide de data based in other selected cell.
Ty

Running from source

I am unable to import the cell editor from the source. It works perfectly fine when using npm install, but when I follow the same instructions after dowloading the package from git it does not work. Is there some preprocessing I have to do first?

Pressing Enter doesn't work in the cells in the same column.

Hello, this library has saved my time a lot. I would like to appreciate your contribution before I report it.

I am using this library in a special case, which uses the autocomplete function only for the first row.
In addition, I use ag-grid as row-based.

When I select a value in the first row, Enter and Tab don't work after the second row.
I handled it by adding the below code to the table and now it works properly.

onCellKeyPress = ({ data, event }) => {
  if (data.field !== "exampleRowFirst" && event.keyCode === 13) {
    for (let cell of this.gridApi.getEditingCells()) {
      this.gridApi.stopEditing();
      this.gridApi.setFocusedCell(cell.rowIndex, cell.column.colId);
    }
  }
};

Thank you.

Interent Explorer support?

I checked the autocomplete package and their demo works on internet explorer. Put the ag-grid autocomplete drop down does not work.

[feature request] Allow free text data

Related to #14 #15

This issue is here to be an open discussion to talk about this feature request.

Feature Request:

Desired Behavior:

Allow the user to not be limited by the select fields, and allow him to type free text instead.

Technical implementation:

This options would be handled by a new parameter: strict: bool = true. By default it will be true, and if set to false, it will activate the 'allow free text' behavior.

Change the behavior who are doing the 'autoselection of the first item element' to put is as an parameter option: autoselectfirst: bool = true. This will allow, with the free text option, to choose if you want to enable 'free text' only when no other items are available. Or if you want to use it even if items are available eg:

data = ['toto', 'titi', 'tata']
userType: 't' => autocomplete will select the first element starting with t into the list, here 'toto'. But the user may just want to input 't' and validate with Enter, without selection an option.

It would be nice to also have another parameters who will be a function: freeTextEntered: (cellEditor: AutocompleteSelectCellEditor, item: T)

Who will be triggered when a non-select option is entered. Allowing to for instance, add this new option to the list of the already available ones. Or to perform a 'post' request to create a new item on the server side, ...

Problematic to consider:

  1. Since a select field is not only used to do 'input text' selection, and that I don't want to have many different return types. I think the better is to format the 'new typed text' as an option like another who will look like: {value: inputText, label: inputText}. I think it is the better option, do you see any downside on it ?

Please, be free to comment and say what do you think about the proposed changes.

I will try to get some free time this weekend to implement theses new options.

Clicking on Auto file column clearing the data. Works fine when tab out.

Hi,

Am using the Ag-grid-autocomplete.

I have set the strict to false to allow both autofill and manual free text. This works fine.

After selecting the value, if I edit the autofill data column value and click on other column the auto fill value disappears. However when we tab out from autofill cell it works. Could you please help me in this ?

  1. Auto Fill data added:
    1_AutoFill_Data_added

  2. Click Autofill column try editing:
    2_Click_AutoFill_Column_try_editing

  3. Now click on next column the autofill value clears. Howevere this works fine if I do tab out from auto fill column.
    3_Now_click_on_next_column_AutofillValue_clears

Also can you provide some example on how to use "onFreeTextSelect" in auto fill.

How to accept any data entered?

Hi, thanks for the awesome lib.

How can I make the grid field accept any value, not just the items included in the 'selectData' param ?

Loss value when you click out of the cell

Hello, I have a strange behavior with the use of the mouse that I found also in the demo.

When a cell is valorized, I enter in editing with the mouse, I do nothing and I click out, the cell loses its value. While if it empties voluntarily it works, but if I don't want it it does the same.

Thanks for your help
Nicola

[BUG] Got an Error -> TypeError: undefined is not an object (evaluating 'e.PopupComponent')

Hi,

I'm trying to using ag-grid-autocomplete-editor with CDN but I'm facing an error which is saying "TypeError: undefined is not an object (evaluating 'e.PopupComponent')" when the page loaded.

My HTML file includes:

<script src="https://unpkg.com/@ag-grid-enterprise/[email protected]/dist/ag-grid-enterprise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>

Ag-grid's working fine. What am I doing wrong (probably I'm doing something wrong though) or is there a bug?

Thanks.

Over writing params.data[key]

Hey thanks for working on this component. It seems pretty good. I noticed several of ag-grids built in features expects params.data[key] to return a value. It looks like this has been over written with an object that has value and label. This seems to be fine for the autocomplete but causes issues for many of the ag-grid functions. Is it possible to create another object in params such as params.autocomplete = {'value' :'xxx','label':1} and then store that value into params.data[key].

[BUG] Value being cleared out even though it should have retained the value since there's no changes made

Using the demo given, under the "Ajax country request" column.

When you type 'cana' and hit Tab key, it'll select 'Canada' and move over the right, which is the 'Capital slow request with spinner' column.

Go back to the cell that says 'Canada' and double click on it.
It'll show the cursor that's waiting for input.
Now click on any other cell.
The cell 'Canada' will be cleared out.

The expected behavior is that it should retain whatever was in the cell instead of clearing out the cell.

Take 'Price' column for example, the value in the cell retains after following the steps detailed above.

[FEAT] - Get access to row data inside of fetch

Inside of the fetch of autocomplete, I would like access to row data so I can make http calls based on the row being edited. This is similar to how params currently works with most ag grid functions.

Should it not show all options on click?

Hey. Great job on this. I was wondering if clicking on the cell could should all the values and then filter upon typing would be better user experience?
Also, would this package be compatible with ag-grid-vue?

Thank you for your help!

How can I use it with TypeScript

How can I use it with TypeScript and reactjs
When I install it, it still doesn't recognize it.

image

It is usually solved using:

npm i @types/ag-grid-autocomplete-editor -S

[bug] Handle tab as enter

Since this module is made to work along with ag-grid, we should handle the 'TAB' input as 'ENTER' if an option is already selected.

It will make the input flow more convenient.

Many Editors One Column

According to Docs https://www.ag-grid.com/vue-grid/cell-editing/ we can provide different celleditors to different cells at the same column. How can we achive this ?

But actually this is not working ?

   cellEditorSelector: (params) => {
          if (params.data.typ === "ObjectTypeA") {
            return {
              component: "autocompleteSelectCellEditor",
              params: {
                cellEditorParams: {
                  required: true,
                  selectData: this.selectData,
                  placeholder: "Select an option",
                  autocomplete: {
                    strict: false,
                    autoselectfirst: false,
                  },
                },
              },
            };
          }
          return null;
        },

[FEAT] Multi-Select autocomplete

Is your feature request related to a problem? Please describe.
Consider a use-case where you want to assign multiple roles to a user.

Describe the solution you'd like
Something like Multi option of https://react-select.com/home

Describe alternatives you've considered
Not sure yet.

Everytime the user enters data, [object object] gets written

Hi avallete, great package 👌🏻 Thank you for creating it.

I have the following problem: When the user enters a value, never writes the value, but

{
  value: <entered value>,
  label: <entered value>
}

I'd also like any value to be entered (not only the auto complete suggestions).

Here is my code:

function contactInformationFormatter(params) {
  if (params.value) {
    // Me trying to extract the value so that not `[object object]` gets returned.
    return strings[params.value] || params.value.value || params.value;
  }
  return '';
}

function ContactList({
  autoSuggestions,
  contacts,
  onCellValueChanged,
  searchValue,
}) {
  const columnDefs = R.map(
    R.pipe(x => ({
      headerName: strings[x.name],
      field: x.name,
      valueFormatter: contactInformationFormatter,
      cellEditor: keysThatShouldHaveAutoSuggestions.includes(x.name)
        ? AutocompleteSelectCellEditor
        : componentToCellEditors[x.component],
      cellEditorParams:
        x.component === 'select'
          ? cellEditorParams[x.name]
          : keysThatShouldHaveAutoSuggestions.includes(x.name)
          ? {
              selectData: autoSuggestions[x.name].map(x => ({
                value: x,
                label: x,
              })),
            }
          : null,
      getQuickFilterText: function(params) {
        return x.component === 'select' ? null : params.value;
      },
      cellClassRules: {
        'search-value-found':
          'api.gridOptionsWrapper.gridOptions.quickFilterText && x.toLowerCase().includes(api.gridOptionsWrapper.gridOptions.quickFilterText)',
      },
    })),
    contactInformationCells
  );

Do you have any idea, what I'm doing wrong?

Error: addDestroyableEventListener is not a function

I'm running the latest ag-grid and ag-grid-autocomplete-editor:

ag-grid-autocomplete-editor.ts:105 Uncaught (in promise) TypeError: e.addDestroyableEventListener is not a function
at Object.render (ag-grid-autocomplete-editor.ts:105)
at render (ag-grid-autocomplete-editor.ts:156)
at autocomplete.ts:220
at Array.forEach ()
at x (autocomplete.ts:235)
at autocomplete.ts:423
at _callee9$ (QuickBook.js:597)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:274)
at Generator.prototype. [as next] (runtime.js:97)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)

regenerate full list when previously entered data is deleted

The feature open the list as soon as you enter the edit mode is really nice. It makes sense to me that with this feature if i edit a cell that already has data and I delete all the contents in that cell the autocomplete list should render full original list. However it will show nothing until the first character is entered.

Feature Request: Batch rendering for autocomplete for large set of data

If the list has more than about 500 entries the rendering hangs (It will eventual show up, but a bit laggy). Large drop downs often happen when dealing with lists of people. Is it possible to render in groups. Like only showing the first hundred then more will be rendered if the user scrolls down near bottom.

How to provide custom filter?

Can we provide custom filtering?
Data in my case is like:
arr =
[
{id: 1, login_id: 'abc0d12', person_name:'Doe, Jane'},
{id: 2, login_id: 'abc0d45', person_name:'Master, None'}
]

I want user to enter either login_id or person_name and result should be filtered based on either of these two not just person_name(display value).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.