- Home
- Forum
- Angular - EJ 2
- add New Row with Contextual Search
add New Row with Contextual Search
I am using this Example https://stackblitz.com/edit/angular-efjsmp-ulvs8d?file=app.component.html for adding a new row in the Grid. I am looking at adding a functionality where user clicks on add button. which will bring up blank row ( Demo does exactly that) then for example if user types few characters in customer ID column, then it will show suggested values from master array. Something like how Google search suggest terms.
|
[app.component.html]
<ejs-autocomplete
id="CustomerID"
width="200"
[dataSource]="data"
[fields]="fields"
></ejs-autocomplete> |
|
[app.component.ts]
addRecord() {
this.record = {
OrderID: Number(document.getElementById('OrderID').value),
EmployeeID: Number(document.getElementById('EmployeeID').value),
CustomerID: document.getElementById('CustomerID').ej2_instances[0].value,
Title: document.getElementById('checkvalue').checked,
};
this.grid.addRecord(this.record);
} |
I am looking at the autocomplete functionality within grid cell it self. when you click on Add new Row and it will add blank row. and autocomplete functionality is available for desired cell within row.
your example is looking at the autocomplete outside grid.
Thanks for your update.
Based on your requirement, you want an autocomplete inside the grid cell when you add a new row. your requirement can be achieved by using the `editSettingsTemplate` of the EJ2 Grid.
please refer the below code example:
|
<div class="control-section">
<ejs-grid [dataSource]="data" allowPaging="true" [pageSettings]="pageSettings" [editSettings]="editSettings" [toolbar]="toolbar" (actionBegin)="actionBegin($event)" (actionComplete)="actionComplete($event)" > <e-columns> <e-column field="OrderID" headerText="Order ID" width="120" textAlign="Right" [isPrimaryKey]="true" ></e-column> <e-column field="CustomerName" headerText="Customer Name" width="120" ></e-column> <e-column field="Freight" headerText="Freight" width="120" format="C2" textAlign="Right" ></e-column> <e-column field="OrderDate" headerText="Order Date" width="130" format="yMd" textAlign="Right" ></e-column> <e-column field="ShipCountry" headerText="Ship Country" width="150" ></e-column> </e-columns> <ng-template #editSettingsTemplate let-data> <div ngForm #orderForm="ngForm"> <table class="e-table e-inline-edit" cellspacing="0.25"> <colgroup> <col style="width: 120px;" /> <col style="width: 120px;" /> <col style="width: 120px;" /> <col style="width: 130px;" /> <col style="width: 150px;" /> </colgroup> <tbody> <tr> <td style="text-align: right" class="e-rowcell"> <div class="e-input-group" [ngClass]="{ 'e-disabled': !data.isAdd }" > <input class="e-input e-field" [(ngModel)]="orderData.OrderID" required [attr.disabled]="!data.isAdd ? '' : null" name="OrderID" type="text" (focus)="focusIn($event.target)" (blur)="focusOut($event.target)" #OrderID style="text-align: right" /> </div> </td> <td class="e-rowcell"> <div class="e-input-group"> <input class="e-input e-field" name="CustomerName" [(ngModel)]="orderData.CustomerName" required type="text" (focus)="focusIn($event.target)" (blur)="focusOut($event.target)" #CustomerName /> </div> </td> <td style="text-align: right" class="e-rowcell"> <ejs-numerictextbox name="Freight" id="Freight" [(ngModel)]="orderData.Freight" floatLabelType="Never" ></ejs-numerictextbox> </td> <td style="text-align: right" class="e-rowcell"> <ejs-datepicker id="OrderDate" name="OrderDate" required [(ngModel)]="orderData.OrderDate" floatLabelType="Never" ></ejs-datepicker> </td> <td class="e-rowcell"> <ejs-autocomplete id="ShipCountry" name="ShipCountry" [(ngModel)]="orderData.ShipCountry" [dataSource]="shipCountryDistinctData" [fields]="{ text: 'ShipCountry', value: 'ShipCountry' }" popupHeight="300px" floatLabelType="Never" ></ejs-autocomplete> </td> </tr> </tbody> </table> </div> </ng-template> </ejs-grid> </div> |
Documentation: https://ej2.syncfusion.com/angular/documentation/grid/edit/#template-driven-forms
Please find the attached sample and revert for more queries.
Regards,
Joseph I.
Thanks for the response. Few Questions
- Can it be possible to hook it up with API instead of static data ?
- Will it be possible to give me example using typescript, instead of doing it from HTML, as my code has dynamic columns,
- In your example you have modified other columns using edit templates, Hopefullyi can apply it just for one column instead of all. I am siure answer to this is YES. But still :)
- Do you have bound remote data or local data in your Grid?
- Share with us complete Grid code example?
- Do you want to initialize the Grid column through typescript ?
- If you are using remote data means, can you please share with us which type service used in your Grid?
- Do you want to render autocomplete components for all columns while editing? , if the is not meet your requirement could you please more details about your requirement
- Do you have bound remote data or local data in your Grid? - remote sharepoint REST API
- Share with us complete Grid code example?
- Do you want to initialize the Grid column through typescript ? YES
- If you are using remote data means, can you please share with us which type service used in your Grid?
- Do you want to render autocomplete components for all columns while editing? , No
Code which is not working against ResouceName column. out of the box it applies TOLOWER which is not allowed in Sharepoint REST API. because of which my code is failing to fetch the infromation.
If i can construct my own URL for search or there is another way to search. If I construct my own URL then I will be needing the idea as to how can i pass my search term as user types in data. Also, I am required to populate other columns in grid once user searches name in auto complete and then populate data in other columns like ResourceType, Internal/External etc.
My requirement is very simple. I want to have search functionality in my grid cell. I dont understand whether i am not able to explain or i am not able to understand what you guys are explaining it to me.
I have 2 Tables and 2 APIs. one is master and second is child. When I expand Parent/Master row. I want to bind the Child grid. Which i am able to do it. Now, within this child grid I have add Row functionality. which is working just fine. Once user adds a new row. one of the column needs to have search functinality which will auto complete user's search and suggests some user names. JQUERY can do this really easily....
Please refer to below code in Javascript. Which is working just fine where i am not using syncfusion controls
- 10 Replies
- 5 Participants
-
PD PDev
- Nov 9, 2021 02:43 PM UTC
- Nov 23, 2021 08:54 AM UTC