We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Automatic update grid after autocomplete

Hi All,

I have a grid that has an autocomplete component in one of the columns.

Everithing is working fine, but i wanted for some columns of the grid to be updated after the field with autocomplete is changed. Please see the code bellow:


        function write(args) {

           autoCompleteEle = new ej.dropdowns.AutoComplete({

               allowCustom: true,

               value: args.rowData[args.column.field],

               dataSource: @Html.Raw(Json.Serialize(ViewBag.ItemCode)),

               fields: { value: 'Artigo', text: 'Artigo' },

               popupWidth: '900px',

               headerTemplate:

                '<div class="row">' +

                    '<div class="col-md-3">Item Code</div> ' +

                    '<div class="col-md-9">Item Name</div></div>',

                itemTemplate:

                    '<div class="row">' +

                        '<div class="col-md-3">${Artigo}</div>' +

                        '<div class="col-md-9">${Descricao}</div></div>',

                change: (e) => {

                            I want to change the field ItemName to the value of ${ Descricao }

                }

            });


What i want to implement is that after the field ItemCode is updated the filed ItemName is also updated.

Thanks in advance for your help on this.

Kind regards


5 Replies

JC Joseph Christ Nithin Issack Syncfusion Team March 28, 2023 04:17 PM UTC

Hi Nuno,



Greetings from Syncfusion support.



Based on your query, you want to update the value of other columns based on the value of an edited column. We have already discussed about this in the below documentation. Please refer the below documentation.


Documentation: https://helpej2.syncfusion.com/aspnetcore/documentation/grid/editing/in-line-editing#automatically-update-the-column-based-on-another-column-edited-value


Regards,

Joseph I.



ND Nuno Domingues March 29, 2023 01:11 PM UTC

Hi Joseph,


Thanks for the reply above. Its a workaround, but it was not exactly what i wanted.

What i was asking is similar to multiple columns in EJ1. A way to access other fields from the autocomplete list directly on the change event.

If you see my code, the autocomple is for data Artigo Artigo but the menu also shows the field descricao. What i wanted to know if its possible is to access the value of descricao on the change event.

I can always to a ajax call and return an object and update the grid, but i was wondering if there's a simpler way to access that data since i have it on the list for the autocomplete.

Kind regards



JC Joseph Christ Nithin Issack Syncfusion Team March 30, 2023 07:56 AM UTC

Nuno,


  Before proceeding to the solution, please share the below details so that we will be able to validate further.


  • Complete grid rendering code.
  • Simple issue reproducible sample.
  • Video demo of your requirement.
  • Syncfusion package version.


ND Nuno Domingues May 3, 2023 05:34 PM UTC

Hi,

Thanks for the assistance. I actually have done this a few weeks ago but forgot to reply to you.

I ended up doing like this and it works fine. If you have any suggestions on how to improve feel free.


            autoCompleteEle = new ej.dropdowns.AutoComplete({

                placeholder: 'Artigo',

                floatLabelType: 'Always',

                allowCustom: true,

                value: args.rowData[args.column.field],

                dataSource: @Html.Raw(Json.Serialize(ViewBag.ItemCode)),


                fields: { value: 'Artigo', text: 'Artigo' },


                popupWidth: '900px',

                headerTemplate:

                    '<div class="row">' +

                    '<div class="col-md-3">Item Code</div> ' +

                    '<div class="col-md-9">Item Name</div></div>',

                itemTemplate:

                    '<div class="row">' +

                    '<div class="col-md-3">${Artigo}</div>' +

                    '<div class="col-md-9">${Descricao}</div></div>',

                change: (e) => {


                    $.ajax({

                        type: "POST",

                        url: "/PurchaseOrders/GetItemData",

                        data: {

                            itemCode: e.value,

                            __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value

                        },

                        dataType: "json",

                        success: function (data) {

                            document.querySelector("#GridItemName").value = data[0].Descricao;

                            document.querySelector("#GridUnit").value = data[0].UnidadeBase;

                            if (data[0].MovStock === "S") {

                                $("#GridWharehouse").prop('readonly', false);

                            } else {

                                document.querySelector("#GridWharehouse").value = "";

                                $("#GridWharehouse").prop('readonly', true);

                            }


                        },

                        error: function (result) {

                            alert("The operation resulted in an error");

                        }

                    });

Thanks for the 



JC Joseph Christ Nithin Issack Syncfusion Team May 8, 2023 07:07 PM UTC

Hi Nuno,


  We are glad that you were able to find the solution for your query.


Loader.
Up arrow icon