Grid Add command



In Add mode the name 'Link Type' is not showing for the dropdown column

Also, is there a way to hide a column is ADD and Edit mode only?

 public editSettingsEditSettingsModel = { allowEditing: falseallowAdding: trueallowDeleting: truemode: 'Dialog' };


<ejs-grid [editSettings]='editSettings' [toolbar]='toolbar'
                                        (toolbarClick)='clickHandler($event)' [dataSource]='aEpicLinks'
                                        [allowPaging]='true' [allowSorting]='true' [pageSettings]='pageOptions'
                                        (commandClick)='commandClickLink($event)' (actionBegin)='actionBegin($event)'
                                        (actionComplete)="actionComplete($event)"
                                        (rowSelected)='rowSelectedLink($event)' [allowFiltering]='true'
                                        [filterSettings]='filterOptions'>
                                        
                                        <e-columns>
                                            <e-column field='itemDependencyAssociationId'  textAlign='Left' width=90
                                            [visible]='false' defaultValue='0' >
                                            e-column>
                                            <e-column field='linkType' headerText='Link Type' textAlign='Left' width=90
                                                [edit]='ddParamsP'>
                                            e-column>
                                            
                                            <e-column field='name' headerText='Link Name' textAlign='Left' width=90>
                                            e-column>



                                            <e-column headerText='' width=140 [commands]='commandsLink'>e-column>
                                        e-columns>
                                    ejs-grid>


this.ddParamsP = {
      create: () => {
        this.elem = document.createElement('input');
        return this.elem;
      },
      read: () => {
        console.log("Read");
        return this.dropdownObj.value;
      },
      destroy: () => {
        this.dropdownObj.destroy();
      },
      write: (args: { rowDataanycolumnany }) => {

        this.dropdownObj = new DropDownList({
          dataSource: <any>this.assocTypesDatavalue: (args.rowData as any).linkTypefields: { text: 'name'value: 'id' }
        });
        this.dropdownObj.appendTo(this.elem);
      }
    }
    this.getAssociationTypes();
   
  }






7 Replies

VI vin replied to vin December 4, 2020 03:58 AM UTC



In Add mode the name 'Link Type' is not showing for the dropdown column

Also, is there a way to hide a column is ADD and Edit mode only?

 public editSettingsEditSettingsModel = { allowEditing: falseallowAdding: trueallowDeleting: truemode: 'Dialog' };


<ejs-grid [editSettings]='editSettings' [toolbar]='toolbar'
                                        (toolbarClick)='clickHandler($event)' [dataSource]='aEpicLinks'
                                        [allowPaging]='true' [allowSorting]='true' [pageSettings]='pageOptions'
                                        (commandClick)='commandClickLink($event)' (actionBegin)='actionBegin($event)'
                                        (actionComplete)="actionComplete($event)"
                                        (rowSelected)='rowSelectedLink($event)' [allowFiltering]='true'
                                        [filterSettings]='filterOptions'>
                                        
                                        <e-columns>
                                            <e-column field='itemDependencyAssociationId'  textAlign='Left' width=90
                                            [visible]='false' defaultValue='0' >
                                            e-column>
                                            <e-column field='linkType' headerText='Link Type' textAlign='Left' width=90
                                                [edit]='ddParamsP'>
                                            e-column>
                                            
                                            <e-column field='name' headerText='Link Name' textAlign='Left' width=90>
                                            e-column>



                                            <e-column headerText='' width=140 [commands]='commandsLink'>e-column>
                                        e-columns>
                                    ejs-grid>


this.ddParamsP = {
      create: () => {
        this.elem = document.createElement('input');
        return this.elem;
      },
      read: () => {
        console.log("Read");
        return this.dropdownObj.value;
      },
      destroy: () => {
        this.dropdownObj.destroy();
      },
      write: (args: { rowDataanycolumnany }) => {

        this.dropdownObj = new DropDownList({
          dataSource: <any>this.assocTypesDatavalue: (args.rowData as any).linkTypefields: { text: 'name'value: 'id' }
        });
        this.dropdownObj.appendTo(this.elem);
      }
    }
    this.getAssociationTypes();
   
  }






Need help please


BS Balaji Sekar Syncfusion Team December 4, 2020 03:47 PM UTC

Hi Vin, 
 
Query #1: In Add mode the name 'Link Type' is not showing for the dropdown column 

Based on your query we suspect that you need to display the label name when you add the new record.   

To show the label edit column name in the dropdownlist(which is bind by using cellEditTemplate feature) we suggest you to use write method of cellEditTemplate. 
 
We have created a label selector with a column name and it is prepend to the dropdownlist editing in the write method. Please refer the below code example and sample for more information. 

[normal-edit.component.ts] 
  this.editparams = { 
      create: () => { 
        this.elem = document.createElement("input"); 
        return this.elem; 
      }, 
      read: () => { 
        return this.dropdownObj.text; 
      }, 
      destroy: () => { 
        this.dropdownObj.destroy(); 
      }, 
      write: args => {         
        var label = document.createElement("label"); 
        label.innerText = "CustomerID"; 
        label.style.color = "rgba(0, 0, 0, 0.42)"; 
        label.style.fontWeight = "400"; 
        args.element.parentElement.appendChild(label); 
        var brelem = document.createElement("br"); 
        args.element.parentElement.appendChild(brelem); 
        args.element.parentElement.appendChild(this.elem); 
 
        this.dropdownObj = new DropDownList({ 
          dataSource: <any>orderDatas, 
          value: (args.rowData as any).OrderID, 
          fields: { text: "CustomerID", value: "OrderID" } 
        }); 
 
        this.dropdownObj.appendTo(this.elem); 
      } 
    }; 


Query #2:  is there a way to hide a column is ADD and Edit mode only? 

From above query we are unable to get the exact requirement. So, please share your exact requirement with screenshot or video demo it will help us to provide the proper solution. 

Regards, 
Balaji Sekar 



VI vin December 8, 2020 04:25 AM UTC

It is rendering bit differently for me, 
The 1st dropdown select icon on left side
The 2nd dropdown label is below dropdown
And i see a new line before Save button




<ejs-grid [editSettings]='editSettings' [toolbar]='toolbar'
                                        (toolbarClick)='clickHandler($event)' [dataSource]='aEpicLinks'
                                        [allowPaging]='true' [allowSorting]='true' [pageSettings]='pageOptions'
                                        (commandClick)='commandClickLink($event)' (actionBegin)='actionBegin($event)'
                                        (actionComplete)="actionComplete($event)"
                                        (rowSelected)='rowSelectedLink($event)' [allowFiltering]='true'
                                        [filterSettings]='filterOptions'>
                                        
                                        <e-columns>
                                            
                                            <e-column field='linkType' headerText='Link Type ' textAlign='Left' width=90
                                                [edit]='ddParamsP'>
                                            e-column>
                                           
                                            <e-column field='name' headerText='Link Name' textAlign='Left' width=90
                                                [edit]='ddParamsTasks'>
                                            e-column>



                                            <e-column headerText='' width=140 [commands]='commandsLink'>e-column>
                                        e-columns>
                                    ejs-grid>



this.ddParamsP = {
      create: () => {
        this.elem = document.createElement('input');
        return this.elem;
      },
      read: () => {
        console.log("Read");
        return this.dropdownObj.value;
      },
      destroy: () => {
        this.dropdownObj.destroy();
      },
      write: (args=> {

        var label = document.createElement("label");
        label.innerText = "Link Type";
        label.style.color = "rgba(0, 0, 0, 0.42)";
        label.style.fontWeight = "400";
        args.element.parentElement.appendChild(label);
        var brelem = document.createElement("br");
        args.element.parentElement.appendChild(brelem);

        args.element.parentElement.appendChild(this.elem);

        this.dropdownObj = new DropDownList({
          dataSource: <any>this.assocTypesDatavalue: (args.rowData as any).linkTypefields: { text: 'name'value: 'id' }
        });
        this.dropdownObj.appendTo(this.elem);
      }
    }

    this.ddParamsTasks = {
      create: () => {
        this.elemTasks = document.createElement('input');
        return this.elemTasks;
      },
      read: () => {
        console.log("Read");
        return this.dropdownTasksObj.value;
      },
      destroy: () => {
        this.dropdownTasksObj.destroy();
      },
      write: args => {
        var label = document.createElement("label");
        label.innerText = "Tasks ";
        label.style.color = "rgba(0, 0, 0, 0.42)";
        label.style.fontWeight = "400";
        args.element.parentElement.appendChild(label);
        var brelem = document.createElement("br");
        args.element.parentElement.appendChild(brelem);

        args.element.parentElement.appendChild(this.elem);

        this.dropdownTasksObj = new DropDownList({
          dataSource: <any>this.tasksDatavalue: (args.rowData as any).itemNamefields: { text: 'itemName'value: 'itemId' }
        });
        this.dropdownTasksObj.appendTo(this.elemTasks);
      }
    }



  }



I added one more dropdown to your example




VI vin replied to vin December 9, 2020 02:55 AM UTC

It is rendering bit differently for me, 
The 1st dropdown select icon on left side
The 2nd dropdown label is below dropdown
And i see a new line before Save button




<ejs-grid [editSettings]='editSettings' [toolbar]='toolbar'
                                        (toolbarClick)='clickHandler($event)' [dataSource]='aEpicLinks'
                                        [allowPaging]='true' [allowSorting]='true' [pageSettings]='pageOptions'
                                        (commandClick)='commandClickLink($event)' (actionBegin)='actionBegin($event)'
                                        (actionComplete)="actionComplete($event)"
                                        (rowSelected)='rowSelectedLink($event)' [allowFiltering]='true'
                                        [filterSettings]='filterOptions'>
                                        
                                        <e-columns>
                                            
                                            <e-column field='linkType' headerText='Link Type ' textAlign='Left' width=90
                                                [edit]='ddParamsP'>
                                            e-column>
                                           
                                            <e-column field='name' headerText='Link Name' textAlign='Left' width=90
                                                [edit]='ddParamsTasks'>
                                            e-column>



                                            <e-column headerText='' width=140 [commands]='commandsLink'>e-column>
                                        e-columns>
                                    ejs-grid>



this.ddParamsP = {
      create: () => {
        this.elem = document.createElement('input');
        return this.elem;
      },
      read: () => {
        console.log("Read");
        return this.dropdownObj.value;
      },
      destroy: () => {
        this.dropdownObj.destroy();
      },
      write: (args=> {

        var label = document.createElement("label");
        label.innerText = "Link Type";
        label.style.color = "rgba(0, 0, 0, 0.42)";
        label.style.fontWeight = "400";
        args.element.parentElement.appendChild(label);
        var brelem = document.createElement("br");
        args.element.parentElement.appendChild(brelem);

        args.element.parentElement.appendChild(this.elem);

        this.dropdownObj = new DropDownList({
          dataSource: <any>this.assocTypesDatavalue: (args.rowData as any).linkTypefields: { text: 'name'value: 'id' }
        });
        this.dropdownObj.appendTo(this.elem);
      }
    }

    this.ddParamsTasks = {
      create: () => {
        this.elemTasks = document.createElement('input');
        return this.elemTasks;
      },
      read: () => {
        console.log("Read");
        return this.dropdownTasksObj.value;
      },
      destroy: () => {
        this.dropdownTasksObj.destroy();
      },
      write: args => {
        var label = document.createElement("label");
        label.innerText = "Tasks ";
        label.style.color = "rgba(0, 0, 0, 0.42)";
        label.style.fontWeight = "400";
        args.element.parentElement.appendChild(label);
        var brelem = document.createElement("br");
        args.element.parentElement.appendChild(brelem);

        args.element.parentElement.appendChild(this.elem);

        this.dropdownTasksObj = new DropDownList({
          dataSource: <any>this.tasksDatavalue: (args.rowData as any).itemNamefields: { text: 'itemName'value: 'itemId' }
        });
        this.dropdownTasksObj.appendTo(this.elemTasks);
      }
    }



  }



I added one more dropdown to your example



Any help please?


BS Balaji Sekar Syncfusion Team December 9, 2020 02:01 PM UTC

Hi Vin, 
 
We checked your query with provided the information and we found that you have append the input element(this.elem) instead “this.elemTask” to the editform which is defined in write function in the ddParamsTasks definition. 

We have created sample with multiple dropdown editing using cellEditTemplate feature as given below. 
 
 
If still facing same issue in your end, please replicate the reported problem in above sample/video demonstration of problem and share to us that will help to validate further. 
 
Regards, 
Balaji Sekar 



VI vin December 10, 2020 05:11 PM UTC

Thanks that fixed the issue
How do i force validations to select a value from dropdown when in ADD mode




BS Balaji Sekar Syncfusion Team December 11, 2020 04:39 PM UTC

Hi Vin, 

We are happy hear that issue has been resolved. 

Query: How do i force validations to select a value from dropdown when in ADD mode 

By default we have built-in support for validation in the Grid form which is validate focus out from the input component. As per your query we have enabled the column validation in the ShipCountry column and it is apply the validating ShipCountry’s input component(dropdownlist) while add action. 

Please refer the below code example and sample for more information. 

[app.component.html] 
<ejs-grid #grid [dataSource]='data' allowPaging='true' [pageSettings]='pageSettings' [editSettings]='editSettings' 
    (actionComplete)="actionComplete($event)" [toolbar]='toolbar'> 
    <e-columns> 
      <e-column field='ShipCountry' headerText='ShipCountry' width='120' [edit]='shipCountryparams' 
        [validationRules]="shipcountryValidation"></e-column> 
      <e-column field='CustomerID' headerText='Customer ID' width='150' [edit]='editparams'> 
      </e-column> 
      <e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right' isPrimaryKey='true'> 
      </e-column> 
 
    </e-columns> 
  </ejs-grid> 
[app.component.ts] 
export class NormalEditComponent implements OnInit { 
  @ViewChild("grid") 
  public grid: GridComponent; 
 
 
 this.shipcountryValidation = { 
      required: true 
    };  


                                                https://ej2.syncfusion.com/angular/documentation/grid/edit/#custom-validation  

Please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 


Loader.
Up arrow icon