We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50870
    • 7 Posts
    Hi,

    I need to get list of categories (not modx categories) from migxdb table and put this list into migxTV. Here is the schema of this table:
        <object class="Prices_analizy" table="analizy" extends="xPDOSimpleObject">
            <field key="idx" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="time" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
            <field key="glass" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="category" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="price" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0"/>
        </object>
    

    I've created new TV:
    type - migx
    possible values - @CHUNK getCategoriesAnalizy
    configuration - prices_analizy_categories.

    configuration prices_analizy_categories:
    {
      "formtabs":[
        {
          "MIGX_id":8,
          "caption":"\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c",
          "print_before_tabs":"0",
          "fields":[
            {
              "MIGX_id":37,
              "field":"active",
              "caption":"\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u043e",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"listbox",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"\u0412\u044b\u043a\u043b==0||\u0412\u043a\u043b==1",
              "default":0,
              "useDefaultIfEmpty":1,
              "pos":1
            },
            {
              "MIGX_id":38,
              "field":"category",
              "caption":"",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":2
            }
          ],
          "pos":1
        }
      ],
      "contextmenus":"",
      "actionbuttons":"",
      "columnbuttons":"",
      "filters":"",
      "extended":{
        "migx_add":"",
        "disable_add_item":"",
        "add_items_directly":"",
        "formcaption":"",
        "update_win_title":"",
        "win_id":"prices_analizy_categories",
        "maxRecords":"",
        "addNewItemAt":"bottom",
        "multiple_formtabs":"",
        "multiple_formtabs_label":"",
        "multiple_formtabs_field":"",
        "multiple_formtabs_optionstext":"",
        "multiple_formtabs_optionsvalue":"",
        "actionbuttonsperrow":4,
        "winbuttonslist":"",
        "extrahandlers":"",
        "filtersperrow":4,
        "packageName":"",
        "classname":"",
        "task":"",
        "getlistsort":"",
        "getlistsortdir":"",
        "sortconfig":"",
        "gridpagesize":"",
        "use_custom_prefix":"0",
        "prefix":"",
        "grid":"",
        "gridload_mode":1,
        "check_resid":1,
        "check_resid_TV":"",
        "join_alias":"",
        "has_jointable":"yes",
        "getlistwhere":"",
        "joins":"",
        "hooksnippets":"",
        "cmpmaincaption":"",
        "cmptabcaption":"",
        "cmptabdescription":"",
        "cmptabcontroller":"",
        "winbuttons":"",
        "onsubmitsuccess":"",
        "submitparams":""
      },
      "columns":[
        {
          "MIGX_id":122,
          "header":"\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435",
          "dataIndex":"category",
          "width":400,
          "sortable":1,
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":104,
          "header":"\u0410\u043a\u0442\u0438\u0432\u043d\u043e",
          "dataIndex":"active",
          "width":100,
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"this.renderSwitchStatusOptions",
          "clickaction":"switchOption",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":[
            {
              "MIGX_id":101,
              "name":"\u0412\u043a\u043b",
              "value":1,
              "clickaction":"",
              "handler":"",
              "image":"assets\/components\/migx\/style\/images\/tick.png"
            },
            {
              "MIGX_id":102,
              "name":"\u0412\u044b\u043a\u043b",
              "value":0,
              "clickaction":"",
              "handler":"",
              "image":"assets\/components\/migx\/style\/images\/cross.png"
            },
            {
              "MIGX_id":103,
              "name":"\u0412\u044b\u043a\u043b",
              "use_as_fallback":1,
              "value":0,
              "clickaction":"",
              "handler":"",
              "image":"assets\/components\/migx\/style\/images\/cross.png"
            }
          ],
          "editor":""
        }
      ]
    }
    

    Then I need to get JSON-array with MIGX_id field in chunk getCategoriesAnalizy. Snippet migxLoopCollection returns data in JSON format without MIGX_id field. I decide to write own snippet which adds MIGX_id field to output array. So, in chunk getCategoriesAnalizy I call addMigxId snippet:
    <?php
    $modx->runSnippet('migxLoopCollection',array(
        'packageName'=>'prices',
        'usecustomprefix'=>'1',
        'prefix'=>'mcmp_prices_',
        'classname'=>'Prices_analizy',
        'groupby'=>'category',
        'selectfields'=>'category',
        'toJsonPlaceholder'=>'json'
    ));
    $arr = $modx->getPlaceholder('json');
    $arr = json_decode($arr);
    foreach ($arr as $idx => $row) {
        $num = $idx + 1;
        $row->MIGX_id = "$num";
    }
    return json_encode($arr);
    

    When I load resource with this TV in manager, it show me correct grid. But when I click active icon in grid - nothing happens and I have error message in console:
    Uncaught TypeError: Cannot read property 'createDelegate' of undefined
    

    It is strange, because when I get JSON in chunk with getImageLList snippet (another TV) it works correctly.
      • 50870
      • 7 Posts
      Really nobody knows what is the problem?
        • 4172
        • 5,888 Posts
        you will need to add the handler (additional function to the grid) 'this.handleColumnSwitch' (check the checkbox under the tab 'Handlers')
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 50870
          • 7 Posts
          Thanks, Bruno! I had to find a solution myself.