Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
use jqgrid with angularjs
Tags: angular
28/03/2014
11:45
Avatar
fae
New Member
Members
Forum Posts: 2
Member Since:
28/03/2014
sp_UserOfflineSmall Offline

Hi,

I would like to use jqgrid in an angular project.

But according to http://docs.angularjs.org/misc/faq :

Stop trying to use jQuery to modify the DOM in controllers. Really.

consider removing jQuery from your app. Really.

Is it possible (easy) to write an angular directive for jqgrid?

20/04/2014
11:05
Avatar
lucassus
New Member
Members
Forum Posts: 1
Member Since:
20/04/2014
sp_UserOfflineSmall Offline

Sure it's possible. You could check my open source project https://github.com/9ci/angle-grinder

Basically you could easily write angularjs directive/wrapper for jqGrid plugin and use $http service to feed the grid with data. Both example you'll find in this project.

22/04/2014
11:30
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Thanks for letting us know about this.

Kind Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

23/04/2014
13:16
Avatar
fae
New Member
Members
Forum Posts: 2
Member Since:
28/03/2014
sp_UserOfflineSmall Offline

Hi,

I wrote this small directive (far from ideal, but sufficient for me)

.directive('ngJqgrid', function ($window) {
    return {
        restrict: 'E',
        replace: true,
        scope: {
            config: '=',
            data:   '=?',
            insert: '=?',
            api:    '=?',
        },
        link: function (scope, element, attrs) {
            var table, div;

            scope.$watch('config', function (value) {
                element.children().empty();
                table = angular.element('<table id="' + attrs.gridId + '"></table>');
                element.append(table);
                if (attrs.pagerId) {
                    value.pager = '#' + attrs.pagerId;
                    var pager = angular.element(value.pager);
                    if (pager.length == 0) {
                        div = angular.element('<div id="' + attrs.pagerId + '"></div>');
                        element.append(div);
                    }
                }
                table.jqGrid(value);

                // Variadic API - usage:
                //   view:  <ng-jqgrid ... vapi="apicall">
                //   ctrl:  $scope.apicall('method', 'arg1', ...);
                scope.vapi = function() {
                    var args = Array.prototype.slice.call(arguments,0);
                    return table.jqGrid.apply(table, args);
                };

                // allow to insert(), clear(), refresh() the grid from
                // outside (e.g. from a controller). Usage:
                //   view:  <ng-jqgrid ... api="gridapi">
                //   ctrl:  $scope.gridapi.clear();
                scope.api = {

                    insert: function(rows) {
                        if (rows) {
                            for (var i = 0; i < rows.length; i++) {
                                scope.data.push(rows[i]);
                            }
                            table.jqGrid('setGridParam', { data: scope.data })
                                 .trigger('reloadGrid');
                        }
                    },

                    clear: function() {
                        scope.data.length = 0;
                        table.jqGrid('clearGridData', { data: scope.data })
                            .trigger('reloadGrid');
                    },

                    refresh: function() {
                        table
                            .jqGrid('clearGridData')
                            .jqGrid('setGridParam', { data: scope.data })
                            .trigger('reloadGrid');
                    }
                };
            });

            scope.$watch('data', function (value) {
                table.jqGrid('setGridParam', { data: value })
                     .trigger('reloadGrid')
                ;
            });

        }
    };
})

Kind regards

19/05/2014
23:52
Avatar
seph
Member
Members
Forum Posts: 4
Member Since:
20/04/2012
sp_UserOfflineSmall Offline

Thanks a lot for posting this fae... can you please also provide some sample HTML to use with this directive? 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
51 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information