ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: ohbayashi on April 06, 2017, 01:27:59 pm

Title: I want to initialize the following values after selection, but an error occurs.
Post by: ohbayashi on April 06, 2017, 01:27:59 pm
I want to initialize the following values after selection, but an error occurs.
Please tell me if there is a simple initialization method.

Code: [Select]
{ title: "address", align: "center", colModel: [
    { title: "prefecture", dataIndx: "prefecture", dataType: "string", minWidth: 140,
      editor: {
          type: "select",
          labelIndx: "prefecture",
          valueIndx: "prefecture",
          options: function (ui) {
              var keys = [],
                  opts = [];
              zipcodes.forEach(function(row) {
                  if (keys.indexOf(row.prefecture) < 0) {
                      keys.push(row.prefecture);
//                      opts.push({ prefecture: row.prefecture, city: null, town: null, zip_code: null });    // Error:Uncaught incorrect usage of isValid dataIndx: city
                      opts.push({ prefecture: row.prefecture, city: 1, town: 2, zip_code: 3 });        // Appropriate value. This will not cause an error.
                  }
              })
              return opts;
          },
          dataMap: [ "prefecture", "city", "town", "zip_code" ]
      },
      validations: [
          { type: "minLen", value: 1, msg: "req." }
      ]
Title: Re: I want to initialize the following values after selection, but an error occurs.
Post by: paramvir on April 07, 2017, 09:08:44 am
Option keys may have null values, I don't see anything wrong in it. it can also be verified by entering null option keys in itemlist in this example: https://paramquery.com/pro/demos/datamap

The mentioned error is thrown elsewhere in your implementation. Could you please post a complete test case or a jsfiddle and mention the steps when the error is thrown.

Thanks
Title: Re: I want to initialize the following values after selection, but an error occurs.
Post by: ohbayashi on April 10, 2017, 05:57:33 am
* colModel
Code: [Select]
            { title: "都道府県名", dataIndx: "prefecture", dataType: "string", minWidth: 140,
                filter: {
                    type: "select",
                    condition: "equal",
                    prepend: { "": "-- select --" },
                    options: [],
                },
                editor: {
                    type: "select",
                    labelIndx: "prefecture",
                    valueIndx: "prefecture",
                    options: [],
                    dataMap: [ "prefecture", "city", "town", "zip_code" ]
                },

* grid create.
Code: [Select]
            create: function (evt, ui) {
                // zipcodes load.
                let grid = this;
                $.ajax({
                    url: "/api/zipcodes/",
                    dataType: "json",
                })
                .then(  // 1:success, 2:error
                    function (response) {
                        zipcodes = response.zipcodes;
                    },
                    function () {
                        $("#err_result").text("Data acquisition failed.");
                    }
                )
                .then(
                    function () {
                        // prefecture option set.
                        let column = grid.getColumn({ dataIndx: "prefecture" }),
                            keys = [],
                            opts = [];
                        zipcodes.forEach(function(row) {
                            if (keys.indexOf(row.prefecture) < 0) {
                                keys.push(row.prefecture);
                                opts.push({ prefecture: row.prefecture, city: null, town: null, zip_code: null });
                                // opts.push({ prefecture: row.prefecture });
                            }
                        })
                        column.filter.options = keys;
                        column.editor.options = opts;
                    }

* console.log
Code: [Select]
Uncaught incorrect usage of isValid dataIndx: city
_piv.isValidCell @ pqgrid.dev.js:3979
_piv.isValid @ pqgrid.dev.js:4060
fn.isValid @ pqgrid.dev.js:4045
fn._digestData @ pqgrid.dev.js:5536
fnGrid.updateRow @ pqgrid.dev.js:13546
fn.saveEditCell @ pqgrid.dev.js:5419
(anonymous) @ pqgrid.dev.js:6142
dispatch @ jquery-1.8.3.min.js:2
u @ jquery-1.8.3.min.js:2
trigger @ jquery-1.8.3.min.js:2
(anonymous) @ jquery-1.8.3.min.js:2
each @ jquery-1.8.3.min.js:2
each @ jquery-1.8.3.min.js:2
trigger @ jquery-1.8.3.min.js:2
v.fn.(anonymous function) @ jquery-1.8.3.min.js:2
fn.blurEditor @ pqgrid.dev.js:5208
fn._onContMouseDown @ pqgrid.dev.js:4216
(anonymous) @ pqgrid.dev.js:2661
dispatch @ jquery-1.8.3.min.js:2
u @ jquery-1.8.3.min.js:2
Title: Re: I want to initialize the following values after selection, but an error occurs.
Post by: paramvir on April 10, 2017, 09:16:32 am
It can only be guessed from the stack trace that error is related to the validations in your code. Your code is insufficient to reproduce the error. Kindly post a complete test case or a jsfiddle.