iamisti / mdDataTable

Angular data table complete implementation of google material design based on Angular Material components.
MIT License
524 stars 132 forks source link

using filters in ajax loaded fields #59

Closed e-tip closed 8 years ago

e-tip commented 8 years ago

Hi, Is there a way to apply filters to ajax loaded table content ? something like 'column-keys': [ 'speed | bytes', ], and the possibility to concatenate two fields of the reply into one columns like {{ loaded_bytes }} of {{ total_bytes }}

Obviously i can modify my backend code to implement this but i think that implement it in mdDataTable would be better Thanks in advance

iamisti commented 8 years ago

@e-tip Currently there is no thing like that. And I'm not sure we'd need to add it at the moment. It's very specific and basically you can even do that. Let me show you how.

But I'd suggest to do your data manipulation in your controller's code. You don't have to modify anything in your backend. Let me give you an example. In your paginator function is should be something like this:

    function paginatorCallback(page, pageSize){
            return $http.post('https://api.nutritionix.com/v1_1/search', {
                    'page': page,
                    'pageSize': pageSize
                }).then(function(result){
                    //here using the chainable functionality of the promises you can alter yother response
                    _.each(result.data, function(item, index){
                       result.data[index].speedInBytes = $filter('bytes')(item.speed);

                       //or merge two values into one
                       result.data[index].mergedValue = item.oneValue + '' + item.anotherValue
                   })

                    return {
                        results: result.data,
                        totalResultCount: result.total
                    }
                });

Is that a possible/acceptable solution for you?

e-tip commented 8 years ago

Ohhh, that's so easy that i didn't even thought about it... :+1:

iamisti commented 8 years ago

I'm glad I could help. :) This ticket is closed then.

Cheers