primeng icon indicating copy to clipboard operation
primeng copied to clipboard

DataTable Editable field Type Constraint.

Open jefftham opened this issue 9 years ago • 5 comments

I'm submitting a ... (check one with "x")

[ ] bug report => Search github for a similar issue or PR before submitting
[x] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior

The current version of editable field has no way to limit what users are going to key in.

Expected behavior

Most of the time, programmers are asked to limit the type of input. eg. only allow users to input a number. without framework, input can be limit with HTML attribute. eg. so, the better improvement like: <p-column field="vin" header="Vin" [editable]="true" [type]="number" [min]="1" [max]="5">

What is the motivation / use case for changing the behavior?

Make Prime-Ng more powerful, and usable. So, gain more reputation!!

  • Angular version: 4.0.0
  • PrimeNG version: 2.0.6
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] all browser
  • Language: [all | TypeScript X.X | ES6/7 | ES5] TypeScript 2.2.2

  • Node (for AoT issues): node --version = 7.8.0

jefftham avatar Apr 18 '17 14:04 jefftham

i managed to integrated Inputtext into the p-column & ng-template as

<p-column *ngFor="let col of purCols" [field]="col.field" [header]="col.header" [sortable]="col.sortable" [editable]="col.editable">        
   <ng-template pTemplate let-col let-row="rowData">          
       <input type="number"   pInputText     [(ngModel)]="row[col.field]" />
   </ng-template> 
</p-column> 

However, pInputText overrides the constraint/behaviors of type="number" !!

jefftham avatar Apr 18 '17 15:04 jefftham

This feature request is needed indeed. Only numbers with min-max numbers, or only dates, or a custom regex, etc

MakhouT avatar May 03 '17 09:05 MakhouT

I manage to get this working by implementing an input type=number inside the ng-template as following:

 <p-column field="pricePerThousand" header="Price Per Thousand" [editable]="true">
        <ng-template pTemplate="editor" let-col let-pRequested="rowData">
            <input type="number"  [(ngModel)]="pRequested[col.field]" />
        </ng-template>
    </p-column>

hope this helps!

laslorma avatar Jun 14 '17 14:06 laslorma

Custom editor template can solve this requirement.

cagataycivici avatar Jun 22 '17 13:06 cagataycivici

<p-dataTable #dt [value]="cars" [(selection)]="selectedItems" [editable]="true" (onEditInit)="onEditInit($event)" (onEdit)="onEdit($event)" (onEditCancel)="onEditCancel($event)" (onEditComplete)="onEditComplete($event)"> <p-column [style]="{ 'width':'38px', 'text-align':'center' }" selectionMode="multiple"> <p-column field="vin" header="Vin" [editable]="true"> <p-column field="year" header="Year" [editable]="true"> <input type="number" class="ui-inputtext ui-widget ui-state-default ui-corner-all" [(ngModel)]="rowData[col.field]" [ngModelOptions]="{standalone:true}" (onchange)="dataTableOnBlur($event, col, rowData, rowIndex, dt)" /> <p-column field="color" header="Color" [editable]="true">

On Change event is not firing . I tried blur but its triggering even though the value not changed. Can you help me on this ?

viswa-optimusprime avatar Oct 12 '17 02:10 viswa-optimusprime