<![CDATA[ Custom Renderer for migx (not migxdb) - output is json? - My Forums]]> https://forums.modx.com/thread/?thread=102649 <![CDATA[Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553047
I successfully managed to create a nested migx tv:
A child migx tv, containing a textfield and a dropdown (other tv 1).
A parent migx tv, containing a dropdown (other tv 2) and the child migx tv.

In the table of the parent tv, I want to show 3 columns:
1: value of other tv 2
2: value of child tv where other tv 1 has the value "Default"
3: number of items from child tv.

I think 2+3 would require a custom renderer, so my table code for the parent tv looks like this:
[  {    "header":"Partner",    "dataIndex":"ptv_heading"  },
{    "header":"Default Link",    "dataIndex":"ptv_childtv", "renderer":"this.renderDefItem"  },
{    "header":"Number of Links",    "dataIndex":"ptv_childtv", "renderer":"this.renderCountItems"  } ]


This is the code I wrote for the custom renderers
$renderer['this.renderCountItems'] = "
renderFirst : function(val, md, rec, row, col, s){
        var obj = JSON.parse(val);
        var size = 0, key;
        for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
   return size;
    }        
";

$renderer['this.renderDefItem'] = "
renderFirst : function(val, md, rec, row, col, s){
    var items = JSON.parse(val);
    var results = items.filter(function(obj) { return obj.ctv_country == 'Default'; });
    for (var i = 0; i < results.length; i++) {
        var deflink = results[i].ctv_url;
    }
    if (deflink) {
        var outputtxt = deflink;
    }
    else {
        var outputtxt = '';
    }
    return outputtxt;
    }        
";



My questions:
Where do I have to include my custom renderers? grid.renderer.inc.php or grid.custom.config.inc.php or both?
Unfortunately, my example is not working, no matter where I put my code. the table cell for the column shows the json string instead:

[{"MIGX_id":"1","ctv_url":"dfgdfg","ctv_country":"Default"},{"MIGX_id":"2","ctv_url":"dfgdfgfdg","ctv_country":"Germany"}]


Any ideas?

Perhaps it might be better to use Migxdb instead to create everything via the CMP, however, I am struggling with how to set up a nested migxdb tv. Any help with this would be much appreciated!

Best regards,
Nico
]]>
balihoo Aug 07, 2017, 12:24 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553047
<![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553369 Bruno17 Aug 28, 2017, 11:58 AM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553369 <![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553368 Quote from: Bruno17 at Aug 25, 2017, 03:41 PM
Quote from: balihoo at Aug 25, 2017, 03:11 PM
Hi Bruno,

in the chunk I am calling a snippet:
[[getmigxurl? &val=`[[+links]]`]]



in which chunk?

ahhhh... now I got it. I had to place my snippet call directly in the renderchunktpl field. For some reason I thought I have to use the getimglist snippet there and call my snippet in the tpl chunk. Now everythings works perfectly fine!]]>
balihoo Aug 28, 2017, 11:53 AM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553368
<![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553345 Quote from: balihoo at Aug 25, 2017, 03:11 PM
Hi Bruno,

in the chunk I am calling a snippet:
[[getmigxurl? &val=`[[+links]]`]]



in which chunk?]]>
Bruno17 Aug 25, 2017, 03:41 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553345
<![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553344
in the chunk I am calling a snippet:
[[getmigxurl? &val=`[[+links]]`]]


the snippet code:

<?php
$val = $modx->getOption('val', $scriptProperties, "");
/* //the following json is the field content if I do not use a renderer.
$val = '[{"MIGX_id":"1","url":"asdasd","country":"all","afid":"Standard","releasetitle":"","cnames_ro":"","_this.value":"Standard","cnames":"Überall/Fallback","afidrendered_ro":"","afidrendered":"Standard"},{"MIGX_id":"2","url":"asdasd","country":"DE","afid":"Standard","releasetitle":"","cnames_ro":"","_this.value":"Standard","cnames":"Deutschland","afidrendered_ro":"","afidrendered":"Standard"},{"MIGX_id":"3","url":"asdasda","country":"DE-AT-CH","afid":"Standard","releasetitle":"","cnames_ro":"","_this.value":"","cnames":"GSA","afidrendered_ro":"","afidrendered":"Standard"}]';
*/



$array = json_decode($val, true);
if(!isset($array)) return;

$size=0;
$skey = "url";
$svalue = "Kein Link gefunden.";

$size = count(array_filter($array, function($element){
    return $element['url'] != 'Kein Link gefunden.';
}));

$size = $size-1;

$outputtxt = '+ weitere '.$size.' Links';

echo $outputtxt;


The following json is the field content in the manager if I do use the renderer:

+ weitere 2 Links+ weitere 2 Links+ weitere 2 Links]]>
balihoo Aug 25, 2017, 03:11 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json?page=2#dis-post-553344
<![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553320
To get a working syntax for renderers, you could try to create the columns with the configurator and copy/paste the generated formtabs-json, while opening the config-modal with 'edit raw']]>
Bruno17 Aug 23, 2017, 06:37 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553320
<![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553317
"renderer":"this.renderChunk","renderchunktpl":"[[+example]]"
to work in the MIGX TV? It sounds like everyone gives up and uses the Config instead, which magically works. I'd really like to get it working in the main TV JSON.

Also, where do we configure the
"columnbuttons":""
in the MIGX TV?]]>
rgliberty Aug 23, 2017, 05:50 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553317
<![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553202 Bruno17 Aug 15, 2017, 05:03 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553202 <![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553180 balihoo Aug 14, 2017, 02:46 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553180 <![CDATA[Re: Custom Renderer for migx (not migxdb) - output is json?]]> https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553122
Parent TV:

{
  "formtabs":[
    {
      "MIGX_id":9,
      "caption":"Partnerlinks",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":15,
          "field":"partner",
          "caption":"Partner",
          "description":"",
          "description_is_code":"0",
          "inputTV":"SLServiceDD",
          "inputTVtype":"",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":1
        },
        {
          "MIGX_id":16,
          "field":"links",
          "caption":"Links",
          "description":"",
          "description_is_code":"0",
          "inputTV":"SLShoplinkURL",
          "inputTVtype":"",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":2
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"",
  "actionbuttons":"",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"Partner hinzuf\u00fcgen",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"",
    "update_win_title":"Partner Links",
    "win_id":"lp-shopservices",
    "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":1,
      "header":"Partner",
      "dataIndex":"partner",
      "width":"",
      "sortable":"false",
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":2,
      "header":"Default Link",
      "dataIndex":"linksdef",
      "width":"",
      "sortable":"false",
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"this.renderChunk",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"[[getImageList?\n&value=`[[+links]]`\n&tpl=`migxdefurl`\n]]",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":3,
      "header":"Weitere Links",
      "dataIndex":"alllinks",
      "width":"",
      "sortable":"false",
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"this.renderChunk",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"[[getImageList?\n&value=`[[+links]]`\n&tpl=`migxmoreurl`\n]]",
      "renderoptions":"",
      "editor":""
    }
  ]
}



Child TV (SLShoplinkURL):
{
  "formtabs":[
    {
      "MIGX_id":8,
      "caption":"Shop URL",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":13,
          "field":"url",
          "caption":"Ziel URL",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":1
        },
        {
          "MIGX_id":14,
          "field":"country",
          "caption":"Land",
          "description":"",
          "description_is_code":"0",
          "inputTV":"SLCountryDD",
          "inputTVtype":"",
          "validation":"",
          "configs":"",
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":2
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"",
  "actionbuttons":"",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"Ziel URL hinzuf\u00fcgen",
    "disable_add_item":"",
    "add_items_directly":"",
    "formcaption":"",
    "update_win_title":"Shop URLs",
    "win_id":"lp-shopurls",
    "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":1,
      "header":"Ziel URL",
      "dataIndex":"url",
      "width":"",
      "sortable":"false",
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":2,
      "header":"Land",
      "dataIndex":"country",
      "width":"",
      "sortable":"false",
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    }
  ]
}
]]>
balihoo Aug 10, 2017, 02:02 PM https://forums.modx.com/thread/102649/custom-renderer-for-migx-not-migxdb---output-is-json#dis-post-553122