Need to show concatenated fields in a ng-grid column. Not working.
Hi, I am new to Angular JS, I am trying to display items in a ng-grid. In a particular column, I have to concatenate two different model fields with a "-" sign. Can somebody please help me to have a solution for this?
I tried like this, field : 'rollnumber' + '-' + 'name'; displayName : 'NameRollNumber'
But it is not working :( .
Thanks & Regards, Jewel Jose
Add a function to your row entity
function getRollAndName(){ return this.rollnumber + '-' + this.name; }
field: getRollAndName()
Seems it is not working. I created a function and called that function from field, but it is not working. My grid is bind to an object and I am passing that object to function as function parameter and trying to return concatenate values in that object and return it as a string. field : getRollAndName('student'), displayName : 'NameRollNumber'
and function definition is like this, function getRollAndName(student) { return student.rollnumber + '-' + student.name; }
But it is not working .... :(
Can somebody advice...
see this plunk http://plnkr.co/edit/HeyAdn?p=preview
Hi Swalters,
Thanks very much for the help... It is working now. I made the changes in my code as mentioned by you, and it start working, Thanks Swalters.
Hi Shane,
Is there a way to get that plunk working with asynchronous data? Like $scope.myData = InterestingData.query() // query being used from $resource
@StevenHarlow yep: http://plnkr.co/edit/Tbbx5M?p=preview
@swalters @c0bra thank you both
How can I make this work in the 3.0 version?. I tried the provided method but it didn't worked.
I think the comment above is reasonably clear - what about it is not working?
You need to add a function to each row in your data array, and then set the field to use that function. Did you check the plunker above: http://plnkr.co/edit/HeyAdn?p=preview
Yeah Paul, you are right. The example works perfectly fine. I was committing a mistake.
Thank you for your time and quick response!
Is there any way to call a scope level function rather than an object level function?
I don't particularly want to add the function to the object if I can help it.
I've tried just defining a function within the field statement but that doesn't seem to work.
The way I ended of doing scope level field manipulation was using cell templates. Quick google search brings up, http://brianhann.com/6-ways-to-take-control-of-how-your-ui-grid-data-is-displayed/ which has a decent enough explanation of this works.
Yeah I came across that.. I was looking for something more similar to the way you set mData in the (now legacy) DataTables.
For my specific use case I opted to go with a filter.
Initially I thought at some point I'd need to do something similar to executing a function with mData but after a bit more thought I don't see any real instance where implementing a filter or ,as you mentioned, cell template wouldn't get the job done.
I'm in the midst of upgrading an older app to newer versions of things and was weighing DataTables vs ng-Grid (ui-Grid). Obviously ui-Grid has come a long way.
@c0bra Thank you very much. It works!
I think that the easiest way is to use a simple cell template that has a span {name: "NameRollNumber", cellTemplate: "<span>{{row.entity.rollnumber}} - {{row.entity.name}}</span>"}
I think that this does not break the way angular works. Declaring a function just adds unnecessary extra work and dependencies. I had to surround it with a span so that angular understands that it's an html template and not an html file
@cesee Right. I think It's a better way you want to display a simple template. BTW, cellTemplate: "{{ fieldname }}" will not work.. cellTemplate: "{{ row.entity.fieldname }}" will work. :)
@UnnamedSong Thanks for the correction, I updated the answer.
You're welcome. My pleasure. xD
On Fri, Oct 23, 2015 at 2:43 AM, Cesar Maroun [email protected] wrote:
@UnnamedSong https://github.com/UnnamedSong Thanks for the correction, I updated the answer.
— Reply to this email directly or view it on GitHub https://github.com/angular-ui/ui-grid/issues/723#issuecomment-150302334.
Thanks a lot @cesee It works :)
If someone needs to align it within the cell, use as shown below.Cheers !
cellTemplate: '<div class="ui-grid-cell-contents">{{row.entity.rollnumber}} - {{row.entity.name}}</div>',
You could also do this by using a function for your field in the column def - this is covered in the binding tutorial.
Sent from my iPhone
On 17 Dec 2015, at 2:59 AM, Sampath Lokuge <[email protected]mailto:[email protected]> wrote:
Thanks a lot @ceseehttps://github.com/cesee It works :)
If someone needs to align it within the cell, use as shown below.Cheers !
cellTemplate: '
Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/ui-grid/issues/723#issuecomment-165112809.