Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

dynamic columns with withFnServerData #154

Closed
plane11 opened this issue Dec 17, 2014 · 5 comments
Closed

dynamic columns with withFnServerData #154

plane11 opened this issue Dec 17, 2014 · 5 comments

Comments

@plane11
Copy link

plane11 commented Dec 17, 2014

Hello,
I want fill dtColumns and dtOptions with my ajax call result.

$scope.dtOptions = DTOptionsBuilder.fromSource("sample/json")
            .withFnServerData(function (sSource, aoData, fnCallback, oSettings) {
                oSettings.jqXHR = $.ajax( {
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': function(json){   
                        angular.forEach(json.headers, function(value, key){
                            $scope.dtColumns.push(DTColumnBuilder.newColumn(value).withTitle(value).withClass("center").withOption("width", "100px"));
                        });
                        fnCallback(json.data);
                    }
                });
        });
$scope.dtOptions = DTOptionsBuilder.fromSource("sample/json")
            .withFnServerData(function (sSource, aoData, fnCallback, oSettings) {
                oSettings.jqXHR = $.ajax( {
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': function(json){   
                        angular.forEach(json.headers, function(value, key){
                            $scope.dtColumns.push(DTColumnBuilder.newColumn(value).withTitle(value).withClass("center").withOption("width", "100px"));
                        });

                        $scope.dtOptions.reloadData();
                        fnCallback(json.data);
                    }
                });
        });
$scope.dtColumns =    DTColumnBuilder.newColumn('name').withTitle('Status').withClass("center").notSortable().withOption("width", "15%");

According to 2nd Code, Header Column is not reload. Just 1(Status) exist.

How can i set headers and datas with ajax data?

@l-lin
Copy link
Owner

l-lin commented Dec 17, 2014

Your code is not completed (where ddtype comes from?).
Can you correct them please?

@plane11
Copy link
Author

plane11 commented Dec 17, 2014

Sorry, I modified wrong part.

@l-lin
Copy link
Owner

l-lin commented Dec 17, 2014

It seems you want to change the header dynamically. There is already a bug report #149 about this.

@plane11
Copy link
Author

plane11 commented Dec 18, 2014

Thank you, I'll try it.

@l-lin l-lin closed this as completed Dec 21, 2014
@q640202047
Copy link

if server return empty result,how can i setting an empty datatable?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants