Forum
11:45
28/03/2014
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?
11:05
20/04/2014
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.
11:30
Moderators
30/10/2007
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.
13:16
28/03/2014
Hi,
I wrote this small directive (far from ideal, but sufficient for me)
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
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66