PrimeNg change p-column width with template - primeng

I get following error when trying to set dynamic column width
ERROR Error: Cannot find a differ supporting object '{width: '180px', 'text-align': 'center'}'
<p-dataTable [value]="employees">
<p-header>Employee List</p-header>
<p-column *ngFor="let userColumn of userColumns"
[field]="userColumn.field" [header]="userColumn.title"
[sortable]="userColumn.sort" [style]="userColumn.myStyle">
</p-column>
</p-dataTable>
userColumns defined as
this.userColumns = [
{
'field': 'userId',
'title': 'User Id',
'sort': 'true',
'template': '',
'myStyle' : ''
},
{ 'field': 'jobTitleName', 'title': 'Job title', 'sort': 'true','myStyle': ''},
{ 'field': 'lastName', 'title': 'Last name','sort': 'true', 'myStyle': ''},
{ 'field': 'preferredFullName', 'title': 'First name','sort': 'true', 'myStyle': ''},
{ 'field': 'dateOfJoining', 'title': 'Date of Joining','sort': 'true',
'myStyle': '{width: \'180px\', \'text-align\': \'center\'}'
}

Try changing the definition of your styling and add a single quote around "width"
like this:
this.userColumns = [
{
'field': 'userId',
'title': 'User Id',
'sort': 'true',
'template': '',
'myStyle' : ''
},
{ 'field': 'jobTitleName', 'title': 'Job title', 'sort': 'true','myStyle': ''},
{ 'field': 'lastName', 'title': 'Last name','sort': 'true', 'myStyle': ''},
{ 'field': 'preferredFullName', 'title': 'First name','sort': 'true', 'myStyle': ''},
{ 'field': 'dateOfJoining', 'title': 'Date of Joining','sort': 'true',
'myStyle': '{\'width\': \'180px\', \'text-align\': \'center\'}'
}

Solution is to define myStyle as Object rather than string.
Otherwise even if you don't get differ error but width will not be set.
this.userColumns = [
{
'field': 'userId',
'title': 'User Id',
'sort': 'true',
'template': '',
myStyle : ''
},
{ 'field': 'jobTitleName', 'title': 'Job title', 'sort': 'true','myStyle': ''},
{ 'field': 'lastName', 'title': 'Last name','sort': 'true', 'myStyle': ''},
{ 'field': 'preferredFullName', 'title': 'First name','sort': 'true', 'myStyle': ''},
{ 'field': 'dateOfJoining', 'title': 'Date of Joining','sort': 'true',
myStyle: {width: '180px', 'text-align': 'center'}
}

In primeng 12 they removed colgroup template so if you are using colgroup over the application need to remove because custom width is not working for column if you are using scrollable check migration guide.
link:https://github.com/primefaces/primeng/wiki/Migration-Guide
solution:
you need to add same width for both tags <th [style]="'width':'100px'"> and <td [style]="'width':'100px'">
if you are using dynamic columns then add one more property width like below
[{ header: "Name", field: "name", width: '100px' }] // column object array object
<p-table [value]="data" [columns]="ColumnObjectArray">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns; let idx=index;" class=""
[style]="'width':col.width">{{col.header}}</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-data let-columns="columns">
<tr>
<td *ngFor="let col of columns" [style]="'width':col.width">
{{data[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
try this one you will definitely get the responsive width to table and also you will get the custom column and header width
hope this will work for you

Related

Rowexpander plugin, howto animate the expand effect in Ext 6?

I am wondering if someone know how to animate the expand effect of a rowbody in a gridpanel configured with the rowexpander plugin. I am looking for something like the expand/collapse panel effect. Thanks in advance.
{
ptype: 'rowexpander',
pluginId: 'rowExpanderPlugin',
selectRowOnExpand: true,
rowBodyTpl: new Ext.XTemplate(
'<div class="warning-notice" style="margin: 15px 10px 10px 10px; background-color: gold;"><div class="title">{asunto}</div>{[this.parseMensaje(values.mensaje, values.numero_expediente, values.id_expediente)]}</div>',
{
parseMensaje: function (v, num, idExpediente) {
return v.replace(num, Ext.String.format('{1} <i class="fa fa-external-link" aria-hidden="true"></i>', idExpediente, num));
}
}
)
}
Kindly check this example ExtJS Fiddle
, you can see the + and - sign which expand and collapse the panel
Ext.application({
name: 'Fiddle',
launch: function () {
let store = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Grid',
renderTo: Ext.getBody(),
width: 600,
height: 400,
store: store,
plugins: {
ptype: 'rowexpander',
pluginId: 'rowExpanderPlugin',
selectRowOnExpand: true,
rowBodyTpl: new Ext.XTemplate(
'Name is {name}'
)
},
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email'
}, {
text: 'Phone',
dataIndex: 'phone'
}]
});
}
});

Adding duplicate rows in ui-grid, typing on one field reflecting on all other rows,

created a UI grid with the following fields.
vm.gridRadioTest.columnDefs = [{
name: 'testName',
displayName: 'Test Name',
enableCellEdit: false,
enableColumnMenu: false,
enableSorting: true,
sort: {
direction: uiGridConstants.ASC
}
}, {
name: 'remarks',
displayName: 'Remarks to Lab',
enableCellEdit: true,
enableColumnMenu: false
}, {
name: 'xrayNo',
displayName: 'X-ray No',
enableCellEdit: true,
enableColumnMenu: false
}, {
name: 'testStatus.status',
displayName: 'Status',
enableCellEdit: false,
enableColumnMenu: false,
//cellTemplate: '<a style="cursor: pointer;color: black" class="ui-grid-cell-contents" ng-if="row.entity.resultStatus != null" ng-click="grid.appScope.navigateToPage(row)"><span class=\"glyphicon glyphicon glyphicon-folder-open\" >Report</span></a>'
}, {
name: 'reportStatus',
displayName: 'Report Status',
enableCellEdit: false,
enableColumnMenu: false,
//cellTemplate: '<a style="cursor: pointer;color: black" class="ui-grid-cell-contents" ng-if="row.entity.resultStatus != null" ng-click="grid.appScope.navigateToPage(row)"><span class=\"glyphicon glyphicon glyphicon-folder-open\" >Report</span></a>'
},{
name: 'xrayReferral',
displayName: 'X-Ray Referral',
nableCellEdit : true,
editableCellTemplate: 'ui-grid/dropdownEditor',
cellFilter: 'mapLabSpecimen:this',
editDropdownIdLabel: 'estCode',
editDropdownValueLabel: 'estName',
editDropdownOptionsArray: vm.instituteList,
width: '30%'
// enableColumnMenu: false,
// cellEditableCondition:false
//cellTemplate: '<div class="ui-grid-cell-contents" ng-if="row.entity.resultStatus == \'\'" ><span class=\"glyphicon glyphicon-ok-circle\" style=\"color: green\";>Normal</span></div><div class="ui-grid-cell-contents" ng-if="row.entity.resultStatus == \'Abnormal\' "><span class=\"glyphicon glyphicon-remove-circle\" style=\"color: Red\";>Abnormal</span></div>'
},{
name: 'add',
displayName: '',
enableCellEdit: false,
enableColumnMenu: false,
width: '3%',
cellTemplate: '<div class="ui-grid-cell-contents" ><span class=\"glyphicon glyphicon-plus btn-primary-joli\" ng-click="grid.appScope.reOrderRadioTest()"></span></div>'
}];
Pushing new record in the grid on each add button click
$scope.reOrderRadioTest = function(){
vm.gridRadioTest.data.push(radioTestList);
}
radioTestList is
{"code":null,"message":"Total 1 records found","result":{"testId":4,"testName":"X-RAY","testNameAr":null,"testType":"R","componentTestsYn":null,"testUnitMast":{"id":1089,"ucumCode":"pmol/umol","ucumDesc":"PicoMolesPerMicroMole [Substance Ratio Or Substance Fraction Units]","ucumSynonym":"pmol/umol","mohName":"pmol/umol","activeYn":null},"labTestResultRange":{"testid":4,"description":"DESCRIPTION ","sex":"M","fromAge":0,"fromAgeFactor":"D","toAge":15,"toAgeFactor":"D","low":30,"high":50,"intermediateValue":40,"criticalLow":10,"criticalHigh":80,"printDescription":null,"ruleId":null,"createdBy":null,"createdDt":null,"lastModifiedBy":null,"lastModifiedDt":null,"rangeId":2,"activeYn":"Y","alertLowRange":null,"alertHighRange":null},"refOutYn":null,"doneHereYn":null,"mohTestId":null,"activeYn":"Y"}}
Here all on typing a value one grid field is appearing in all other fields.
Here i typed ff in one field its reflected in all other rows.
I can see internally it using hashkey, How can I modify that
I have found the solution for it:
In function to add row, add the initialization of radioTestList variable.
$scope.reOrderRadioTest = function(){
var radioTestList= {"remarks":'',"testName":''};
vm.gridRadioTest.data.push(radioTestList);
}
Working Plunker is here: http://plnkr.co/edit/Vnn4K5DcCdiercc22Vry?p=preview

Select option in Angular xeditable and Angular Formly

I don't know how to give e-ng-options of xeditable in angular Formly.
Here is the formly Config:
formlyConfig.setType({
extends: 'select',
template: '<div><span editable-select="model[options.key]" e-ng-options="" e-name="{{::id}}">{{ model[options.key] || "empty" }}</span></div>',
name: 'editableSelect'
});
Here is the select value:
{
className: 'col-xs-12 col-sm-6',
type: 'editableSelect',
key: 'gender',
templateOptions: {
label: 'Gender',
options: [
{name: 'Male', value: 'male'},
{name: 'Female', value: 'female'}]
}
}
Pls look at JSBIN
I just figured it out.
formlyConfig.setType({
extends: 'select',
template: '<div><span editable-select="model[options.key]" e-ng-options="s.value as s.name for s in {{options.templateOptions.options}}" e-name="{{::id}}" e-placeholder="{{options.templateOptions.placeholder}}">{{ model[options.key] || "empty" }}</span></div>',
name: 'editableSelect'
});
Refered xeditable

smart table +Angular js

I am using Smart-table to show reports to the user with Angular js.
Now,I want to customize table header and want a colspan in smart table 's header.
Does anyone know about this?Is it possible?
Please share example,plunker if anyone have achieved this
You can have whatever template you want in cellTemplate attr, where I have concatenated both first name and last name.
Like I have used,
scope.columnCollection = [
{ label: 'Name', map: 'FirstName', validationAttrs: 'required', validationMsgs: '<span class="error" ng-show="smartTableValidForm.FirstName.$error.required">Required!</span>',cellTemplate:'<div class="name"><span>{{dataRow.FirstName +" "+dataRow.LastName}}</span><div>'}, //have whatever template you want and your custom css
//{ label: 'Last Name', map: 'LastName' },
{ label: 'User Name', map: 'UserName', validationAttrs: 'required' },
{ label: 'Password', map: 'Password', noList: true, editType: 'password' },
{ label: 'Customer', map: 'CustId', optionsUrl: '/GetCusts', editType: 'radio' },
{ label: 'Role', map: 'RoleId', optionsUrl: '/GetRoles', editType: 'select', defaultTemplate: '<option value="" ng-hide="dataRow[column.map]">---</option>', validationAttrs: 'required', validationMsgs: '<span class="error" ng-show="smartTableValidForm.RoleId.$error.required">Required!</span>' }, // NOTE: small hack which enables defaultTemplate option :)
{ label: 'E-mail', editType: 'email', map: 'Email' },
{ label: 'Cell Phone', map: 'Mobilephone', noEdit: true, validationAttrs: 'required' },
{ label: 'Locked', map: 'IsLocked', cellTemplate: '<input disabled type="checkbox" name="{{column.map}}" ng-model="dataRow[column.map]">', editType: 'checkbox', noAdd: true }
];
In css you can have your custom Css.
Please have a look at this
plunker
Hope this solves your problem :)
Based on the documentation you need to add something like this:
app.controller('basicsCtrl', ['$scope', function (scope) {
scope.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever#gmail.com'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou#gmail.com'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef#gmail.com'}
];
scope.columnCollection = [
{label: 'First Name', map: 'firstName'},
{label: 'same same but different', map: 'firstName'},
{label: 'Last Name', map: 'lastName'}
];
}]);
Your columnCollection will adjust the labels based on the mappings.

How to get parent node in angular

I loop an array inside another array in angular.
fields:
[
{
label: 'First Name',
name: 'firstname',
key: '',
type: 'text',
//fixa requierd i templatesen
required: true
},
{
label: 'Last Name',
name: 'lastname',
key: '',
required: true,
},
{
label: 'Email',
name: 'email',
key: '',
required: true,
type: 'email',
},
{
key: 'test',
type: 'radio',
labels:
[
{
name: 'media',
label: 'Media'
},
{
name: 'frilans',
label: 'Frilans'
}
],
}
],
Whilst looping through field.labels, I want to access it's sibling "key". I tried using $parent scope, but that will include the entire scope. Then angular doesn't know what key it should use.
<div ng-repeat="field in fields">
<div ng-repeat="subfield in field.labels">
<!-- gets you parent's key -->
{{field['key']}}
<!-- you can play around with $index to reach the parent's siblings -->
<!-- just make sure index is in the range though -->
{{fields[$parent.$index - 1]['key']}}
{{fields[$parent.$index + 1]['key']}}
</div>
</div>

Resources