I am new to angular and have been researching Clarity as the UI component..First thing I was toying with was Clarity 'Datagrid'.
Here I wanted to make a generic component which can be configured with something like a 'columnModel' and 'data' both of which will come from backend. which will be used in angular component structural directives (*ngFor etc) to display the datagrid. Here is what I came up with ...
Definitions in app.component.ts
columnModel = [
{header:'Id',dataIndex:'id','width':50},
{header:'Name',dataIndex:'name','width':100},
]
data : [
{id: 1, name: 'Name1', age: 1, rem: 'aaassssssssssssss'} ,
{ id: 2, name: 'Name2', age: 1, rem: 'aaassssssssssssss'},
{ id: 3, name: 'Name3', age: 1, rem: 'aaassssssssssssss'},
]
So here is what I did.(for the lack of better understanding of Clarity n Angular perhaps)..I used jQuery....
On 'ngOnInit' of the host component , I used jquery to set 'width' of 'data-columns' and 'data-cells' within each result row..based on 'colModel' above.. It seems WORKING!!!!
jQuery Code:
ngOnInit() {
const jqModel = this.colModel;
$(document).ready(function() {
$(".datagrid-column").each(function(indx) {
$(this).attr("style",function(i,v){return "max-width:" +
jqcolModel[indx].width +"px;width:" +
jqcolModel[indx].width+"px;"});
});
$(".datagrid-row-master").each(function(indx) {
$(this).children().each(function(indx) {
$(this).attr("style",function(i,v){return "max-width:" +
jqcolModel[indx].width +"px;width:" +
jqcolModel[indx].width+"px"});
});
});
}
My question to you experts is 'Is this a best practise ?' OR is there a better way to achieve this..
Thanks in advance for guding me.