Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gowthamKs opened this issue Jan 21, 2020 · 3 comments
Closed
Labels
question Further information is requested

Comments

@gowthamKs
Copy link

gowthamKs commented Jan 21, 2020

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.

@hbthanki
Copy link

Try valueFormatter like this
#49 (comment)

@avallete avallete added the question Further information is requested label Jan 22, 2020
@gowthamKs
Copy link
Author

gowthamKs commented Jan 22, 2020

Thanks hbthanki.

using valueFormatter am able to solve for one scenario.

Started working:

  1. Auto fill value selected from the dropdown. In this case am able to get back the value from valueFormatter.
valueFormatter: (params) => {
              if (params.value) {
                  return params.value.label || params.value.value || params.value;
              }
              if(params.data)
                return params.data.Operation_Value;

              return "";
          }, 

Not working: I have set the strict to false, able to accept the free text. After adding free text click on other column, the auto fill column value disappears.

  1. Free text vale added:
    image

  2. Click on other column
    image

Note: Same scenario works fine if I do tab out.

Below is my full code:

{
          headerName: "Raw Material",
          field: "Operation_Name",
          cellEditor: AutocompleteSelectCellEditor,
          cellEditorParams: {
              autocomplete: {
                  input: document.getElementById("Operation_Name"),
                  fetch: (cellEditor, text, update) => {
                        let match = text.toLowerCase() || cellEditor.eInput.value.toLowerCase();
                        if(match && match.length > 2)
                        {
                          
                          let xmlHttp = new XMLHttpRequest();
                          xmlHttp.onreadystatechange = () => {
                              if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
                                  let data = JSON.parse(xmlHttp.responseText);
                                  let items:any[] = data.map(d => ({ value: d.Operation_Name, label: d.Operation_Name, unitcost: d.UnitCost, quantity: d.Quantity, Operation_Value:d.Operation_Value }));
                                  update(items);
                                }

                                if (xmlHttp.status === 404) {
                                    update(false);
                                }
                          };
                          let url: string = environment.API_BASE_URL + '/EditDisplay/PopulateRawMaterials/' + match;
                          xmlHttp.open("GET", url, true);
                          xmlHttp.send(null);
                        }
                  },
                  strict: false,
                  autoselectfirst: false,               
              },
              placeholder: 'Select a Raw material',
          },
          valueFormatter: (params) => {
              if (params.value) {
                  return params.value.label || params.value.value || params.value;
              }
              if(params.data)
                return params.data.Operation_Value;

              return "";
          },
          editable: true,

        },

@gowthamKs
Copy link
Author

Am able to solve the issue by updating the cellEditor.currentItem value.

fetch: (cellEditor, text, update) => {
                        let match = text.toLowerCase() || cellEditor.eInput.value.toLowerCase();
                        
                        if(match && match.length > 2)
                        {
                          
                          let xmlHttp = new XMLHttpRequest();
                          xmlHttp.onreadystatechange = () => {
                              if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
                                  let data = JSON.parse(xmlHttp.responseText);
                                  let items:any[] = data.map(d => ({ value: d.Operation_Name, label: d.Operation_Name, unitcost: d.UnitCost, quantity: d.Quantity, Operation_Value:d.Operation_Value }));
                                  if(items.length == 0){
                                    cellEditor.currentItem = match;
                                  }
                                  update(items);
                                }

                                if (xmlHttp.status === 404) {
                                    update(false);
                                }
                          };
                          let url: string = environment.API_BASE_URL + '/EditDisplay/PopulateRawMaterials/' + match;
                          xmlHttp.open("GET", url, true);
                          xmlHttp.send(null);
                        }
                  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants