On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Sean Kimball Reply #1, 1 year ago
    I have a listbox type formtab working just fine, it adds/edits etc from the popup form:

    {
              "MIGX_id":52,
              "field":"category",
              "caption":"Category",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"listbox",
              "validation":"required",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"@EVAL return 'Choose Category==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'projects','classname'=>'ProjectCategory','tpl'=>'@CODE:[[+category]]==[[+id]]','outputSeparator'=>'||'));",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":3
            },


    So you can see it's getting it's options from a database table:

    <object class="ProjectCategory" table="bigblock_project_category" extends="xPDOSimpleObject">
            <field key="category" dbtype="char" precision="50" phptype="string" null="false" />   
            <field key="sort" dbtype="int" precision="10" phptype="integer" null="false" default="0" /> 
            <aggregate alias="Project" class="Project" local="id" foreign="category" cardinality="many" owner="local" default="0" />   
        </object>


    this works great - shows the options - everything is happy.


    Now, I found a couple articles & posts on how to render the name of the category (rather than it's id) in the migx grid view column, seems straight forward.

    HOWEVER:

    I need the Category in the grid column view to be a listbox (select field) that is editable from the grid.

    How is that done?

    **UPDATE**
    So somehow this is now "kind of" working if I use the joined class_field as the column field name, and it shows the category name in the grid view - great... HOWEVER, if I click/double click on the item the drop down list is blank. If I change "dataIndex":"ProjectCategory_category", to "dataIndex":"category", the drop down list is correctly populated AND I can change/edit the items (and verify they are correct in the database)
    {
          "MIGX_id":13,
          "header":"Project Category",
          "dataIndex":"ProjectCategory_category",
          "width":"",
          "sortable":true,
          "show_in_grid":1,
          "customrenderer":"",
          "renderer":"",
          "clickaction":"switchOption",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":"this.listboxEditor"
        },


    So one step further, all I need now is to know how to render the category name correctly AND have the listbox correctly populated. [ed. note: sean69 last edited this post 1 year ago.]
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
    • Change field key "category" in DB, for example on "sub_category".
      <object class="ProjectCategory" table="bigblock_project_category" extends="xPDOSimpleObject">
          <field key="sub_category" dbtype="char" precision="50" phptype="string" null="false" />   
          <field key="sort" dbtype="int" precision="10" phptype="integer" null="false" default="0" /> 
          <aggregate alias="Project" class="Project" local="id" foreign="category" cardinality="many" owner="local" default="0" />   
      </object>
      

      And accordingly change "[[+category]]" here:
      "inputOptionValues":"@EVAL return 'Choose Category==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'projects','classname'=>'ProjectCategory','tpl'=>'@CODE:[[+sub_category]]==[[+id]]','outputSeparator'=>'||'));",
      

      And finally
          {
            "MIGX_id":13,
            "header":"Project Category",
            "dataIndex":"category",
            "width":"",
            "sortable":true,
            "show_in_grid":1,
            "customrenderer":"",
            "renderer":"this.renderChunk",
            "clickaction":"",
            "selectorconfig":"",
            "renderchunktpl":'[[migxLoopCollection? &packageName=`projects` &classname=`ProjectCategory` &where=`{"id":"[[+category]]"}` tpl=`@CODE:[[+sub_category]]`]]',
            "renderoptions":"",
            "editor":"this.listboxEditor"
          },
      

      • And don't forget to rename the field "category" to "sub_category" in the table "bigblock_project_category".
        • I actually did solve this by using a chunk in the renderchunk template for the category column:

          [[!projects? &function=`getListBoxOption` &alias=`ProjectCategory` &object_id=`[[+ProjectCategory_id]]`php &return=`category`]]

          It just calls a snippet that loads my projects class & passes the scriptproperties to it...

          public function getListBoxOption($scriptProperties){
          
          	$output = '';
          
          	$alias = (isset($scriptProperties['alias'])) ? $scriptProperties['alias'] : FALSE;
          
          	$object_id = (isset($scriptProperties['object_id'])) ? $scriptProperties['object_id'] : FALSE;
          
          	$return_column = (isset($scriptProperties['return_column'])) ? $scriptProperties['return_column'] : FALSE;
          
          	if(!$alias || !$object_id || !$return_column){ 
          		return 'Missing object parameters.'; 
          	}
          
          	$option = $this->modx->getObject($alias, $object_id);
          
          	if($option){
          
          		return $option->get($return_column);
          
          	}else{
          		return ' No options found.';
          	}
          
          	 return;
          
          }
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525