Author Topic: set column value programmatically  (Read 1638 times)

x1484

  • Newbie
  • *
  • Posts: 1
    • View Profile
set column value programmatically
« on: September 15, 2020, 07:46:25 pm »
Hello,

My grid is an inline editing grid, I started based on this example :
https://paramquery.com/demos/editing_custom

The 1st column is an article code (editable), the 2nd column being the article description (read-only)

1st column being an autocomplete field based on a PHP JSON mysql query, this column works as expected but when i get the result i would like to set the description cell to the right value.

How can i achieve this ? where is it better to set the column in the validations or in the autocomplete editor definition ?  I have put the code fragment below.

Thanks so much,
FX



var autoCompleteEditor = function (ui) {
            var $inp = ui.$cell.find("input");

            //initialize the editor
            $inp.autocomplete({
                appendTo: ui.$cell, //for grid in maximized state.
                source: function (query, result) {
                     $.ajax( {
                              url: '/getArticlesCodes.php',
                              cache: false,
                              async: false,
                              data:'art_code=' + query.term,           
                              dataType:"json",
                              type:"POST",
                              success: function (data) {

                                       result ( $.map( data,    function (item) {
                                                            return {    art_code: item.art_code,
                                                                     art_desc: item.art_desc,                                                                      
                                                                     label: item.art_code,
                                                                     value: item.art_code
                                                            };
                                                         }
                                                  )
                                             );
                                    }
                           } );
               },
                selectItem: { on: true }, //custom option
                highlightText: { on: true }, //custom option
                minLength: 0
            }).focus(function () {
                //open the autocomplete upon focus               
                $(this).autocomplete("search", "");
            });
        }
       
      
      
        var colM = [
            {    title: "Article Code", dataIndx: "art_code", width: 50,
                editor: {
                    type: "textbox",
                    init: autoCompleteEditor
                },
                validations: [
                    { type: 'minLen', value: 1, msg: "Required" },
                    { type: function (ui) {
                        var value = ui.value,
                            _found = false;

                        $.ajax({
                            url: '/checkArticleCode.php',
                            data: 'art_code=' + value ,
                            async: false,
                     type:"POST",
                            success: function (response) {
                                if (response == "true") {
                                    _found = true;
                           
                           // set description here ?
                                }
                        else {
                           // empty description here ?
                        }
                            }
                        });
                  
                        if (!_found) {
                            ui.msg = value + " not found in list";
                            return false;
                        }
                    }
                    }
                ]
            },
         
         { title: "Description", width: 100, dataIndx: "art_desc", editable: false }
   
      ];