I have a table that I created using jqGrid. I am planning to add a popover functionality, so that when a user click on a cell / grid, then a custom popover is displayed. And I am planning to use the popover from angular ui bootstrap.
I have my grid, and I also have my button that can display a pop over. but when I tried to combine both, it doesn't work. I tried to do this with one of my colModel:
formatter: function(cellvalue, options, rowObject){
return "<button class='btn btn-primary' popover-placement="top" ng-click='ctrl.handle()'>"+cellvalue+"</button>";
}
I have my controller that include angular pop-over as the dependency, but this doesn't work. Is this possible?
I should start with the words that I'm not angular developer and I have never used popover before. So the code which I post below could be not good enough from the angular point of view. Nevertheless it works and it do what you need. Having working code you can improve it probably.
The demo display popover on click on the custom button, which stay opened. Additionally
alert
message will be displayed from the JavaScript function bound usingng-click
:It uses the following HTML markup
and the following JavaScript code which contains from three parts. In the first one do the standard thing
it's important just don't forget to include
"ui.bootstrap"
module required forpopover
.In the second part one use
myApp.directive
with$compile
as parameter, which are used for compiling the grid twice: once before placing an empty<table>
on the HTML page (in<ng-jq-grid>...</ng-jq-grid>
) and once more inside ofloadComplete
:I used free jqGrid 4.8 in the demo, so one don't need to generate and id for the
<table>
element. If you have to use an old version of jqGrid then you should replace the lineto something like
The options
autoResizing
andautoresizeOnLoad
are specific for free jqGrid and follows setting of the width of the columns based on the width of the data in the column. The options are described in the readme and in the wiki.In the last part of the code I use
myApp.controller
to initialize$scope.config
and$scope.data
with initial data.The custom formatter looks like
I hope that I commented the most important parts of the code.