How to create conditionally dynamic html in ui-grid (like row which having input box, select box and submit button)

533 views
Skip to first unread message

Deepak Patidar

unread,
Sep 1, 2016, 12:58:57 AM9/1/16
to UI-Grid Support

I am trying to generate above image UI which having rows with input box, select box and submit button and pretty good I am able to create such UI, But the issue is that I want it dynamic mean I am using switch case for distinguish this with input type.


         for(var i = 0; i < $scope.rows.length; i++) {


            for(var j = 0; j < $scope.customColumns.length; j++) {

                var customColumn = $scope.customColumns[j];

      

                switch(customColumn.inputType) {

                    case 'string':

                        customColumn['cellTemplate'] = '<div class="ui-grid-cell-contents"><input type="text" ng-if="row.entity.status  ===  \'readyForAssignment\'" class="sample-id                          form-control" ng-model="row.entity[customColumns.field]" ng-disabled="row.entity.disable"/></div>';

                        customColumn['width'] = 130;

                        break;

                    case 'dropdown':

                        customColumn['cellTemplate'] = '<div class="ui-grid-cell-contents"><select ng-if="row.entity.status  ===  \'readyForAssignment\'" 

                        data-ng-model="row.entity[customColumns.field]" class="form-control assigned-test" 

                       data-ng-options="item as item for item in grid.appScope.[customColumns.field]+'List' track by item" ng-disabled="row.entity.disable">

                       <option value="" selected hidden /></select></div>';

                        customColumn['width'] = 120;

                        break;

                    case 'date':

                        customColumn['cellTemplate']= '<div class="ui-grid-cell-contents"><mdp-date-picker  ng-if="row.entity.status  ===  \'readyForAssignment\'" 

                        mdp-placeholder="mm/dd/yyyy" mdp-open-on-click mdp-max-date="grid.appScope.currentDate" mdp-format="MM/DD/YYYY"

                         ng- model="row.entity[customColumns.field]"> </mdp-date-picker> </div>';

                        break;

                    case 'submit-button':

                        customColumn['cellTemplate'] = '<div class="ui-grid-cell-contents"><button  ng-if="row.entity.status  ===  \'readyForAssignment\'" class="btn btn-sm fs-                                 button  submitBtn" ng-disabled="row.entity.disable || !row.entity.testPanel || !row.entity.accessionId || !row.entity.sampleReceivedDate"

                        ng-click="grid.appScope.submitTestPanel(row.entity, grid.renderContainers.body.visibleRowCache.indexOf(row))"> {{row.entity.submitBtnLabel}} </button>                           </div>';

                        customColumn['width'] = 100;

                        break;

                    default:

                        customColumn['cellTemplate'] = '<div class="ui-grid-cell-contents">{{COL_FIELD}}</div>';

                }

           

             }

          }
Here suppose we got input type as "string" then it will generate two input box with there ng-model name which is fetched from row.entity[customColumns.field] and same thing with drop down but the issue is how to generate the select box from dynamic array name so what I want  if the customColumns.field equal  "user"  then it should be like
   data-ng-options="item as item for item in grid.appScope.[customColumns.field]+'List'  :====> after replace value of customColumns.field 
   data-ng-options="item as item for item in grid.appScope UserList" so it would be dynamic for every input type of dropdown.

So please suggest how can I achieve this.  

kra.y...@gmail.com

unread,
Sep 7, 2016, 10:24:34 AM9/7/16
to UI-Grid Support
I've created a demo a long time ago doing something similar: https://plnkr.co/edit/b6qZ1rOF8yBwhWETAuME
It shows how to setup a dynamic list in a ui-grid cell (or anywhere for that matter). 
Note the usage of the template as well as the usage of filters.
If you do not expect your enums to change (too) frequently, you can avoid using filters in your template and just use them when the column def is populated.

Reply all
Reply to author
Forward
0 new messages