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_TopicIcon
improved print grid function.
25/09/2012
01:01
Avatar
nelsonm
Michigan, USA
Member
Members
Forum Posts: 106
Member Since:
20/08/2011
sp_UserOfflineSmall Offline

Hi all,

I improved the "setPrintGrid" function a bit.  You no longer have to manually define the ".hide" css class or the print container div.  The "setPrintGrid" function now does that for you.  All you have to do is create the "print-grid.css" file, add the function code to a javascript file and place the function call after any and all grid definitions.

For those who want to be able to print a jqGrid grid, i'd like to offer a nice solution. Even though you only have to specify the main grid id, any sub grids nested within the main grid print out nicely as well. All of this is done on the client side in javascript.

The function adds a print button to the end of the standard jqGrid buttons on the left side of the navigation bar and binds the button to the print function on click. The function uses jQuery and jqGrid methods as well as the third party "printElement" plugin to accomplish the task.

Follow the steps below to set it up.

1. download and install Erik Zaadi's "printElement" plugin at: http://projects.erikzaadi.com/…..038;hellip;..ntElement/ .

2. create a "print-grid.css" file that contains entries to display grid lines on print.  the "print-grid.css" file should NOT be defined on the index or any other page.  It should just exist in the css folder of the site and be called from the "printElement" plugin.

#prt-container table {
    border-collapse:collapse;
}

#prt-container th,
#prt-container td {
    border:1px solid black;
}

3. add the "setPrintGrid" function call to the end of your grid definition but within the "document ready" function. The function parameters are (grid_id, pager_id, button_title)

$(function() {

// example jqGrid
$('#tab4-grid').jqGrid({
.
pager: '#tab4-pager',
toppager: true, // comment out if you don't want the the top nav bar.
.
});

// setup grid print capability. Add print button to navigation bar and bind to click.
setPrintGrid('tab4-grid','tab4-pager','Customer Grid');

});

4. add the "setPrintGrid" function definition to some javascript file with a global namespace.

    // setup grid print capability.  Add print button to navigation bar and bind to click.
    function setPrintGrid(gid,pid,pgTitle){
        // print button title.
        var btnTitle = 'Print Grid';

        // setup print button in the grid top navigation bar.
        $('#'+gid).jqGrid('navSeparatorAdd','#'+gid+'_toppager_left', {sepclass :'ui-separator'});
        $('#'+gid).jqGrid('navButtonAdd','#'+gid+'_toppager_left', {caption: '', title: btnTitle, position: 'last', buttonicon: 'ui-icon-print', onClickButton: function() {    PrintGrid();    } });
    
        // setup print button in the grid bottom navigation bar.
        $('#'+gid).jqGrid('navSeparatorAdd','#'+pid, {sepclass : "ui-separator"});
        $('#'+gid).jqGrid('navButtonAdd','#'+pid, {caption: '', title: btnTitle, position: 'last', buttonicon: 'ui-icon-print', onClickButton: function() { PrintGrid();    } });
    
        function PrintGrid(){
            // attach print container style and div to DOM.
            $('head').append('<style type="text/css">.prt-hide {display:none;}</style>');
            $('body').append('<div id="prt-container" class="prt-hide"></div>');

    
            // copy and append grid view to print div container.
            $('#gview_'+gid).clone().appendTo('#prt-container').css({'page-break-after':'auto'});

            // remove navigation divs.
            $('#prt-container div').remove('.ui-jqgrid-toppager,.ui-jqgrid-titlebar,.ui-jqgrid-pager');

            // print the contents of the print container.    
            $('#prt-container').printElement({pageTitle:pgTitle, overrideElementCSS:[{href:'css/print-container.css',media:'print'}]});

            // remove print container style and div from DOM after printing is done.
            $('head style').remove();
            $('body #prt-container').remove();
        }
    }

I hope this helps.

25/09/2012
01:26
Avatar
nelsonm
Michigan, USA
Member
Members
Forum Posts: 106
Member Since:
20/08/2011
sp_UserOfflineSmall Offline

Here is my jqgrid screen.

Image Enlarger

Here is an image of a work order grid printout with subgrids.

printout of gridImage Enlarger

25/09/2012
01:36
Avatar
nelsonm
Michigan, USA
Member
Members
Forum Posts: 106
Member Since:
20/08/2011
sp_UserOfflineSmall Offline

Sorry, i made a little error...

Please name the css file "print-container.css" instead of "print-grid.css".  The function will still work but you won't get any grid lines if you don't name the css file "print-container.css".

21/11/2012
22:05
Avatar
ginak1004
New Member
Members
Forum Posts: 1
Member Since:
21/11/2012
sp_UserOfflineSmall Offline

I tried this and it works all fine except Chrome.

It works fine at IE and firefox, but when i use Chorme, i can't see any grid lines.

Could you help me?

Thanks

21/11/2012
23:08
Avatar
nelsonm
Michigan, USA
Member
Members
Forum Posts: 106
Member Since:
20/08/2011
sp_UserOfflineSmall Offline

yes, i noticed the issue as well.  Unfortunetly, I don't have time to look into it at the moment.

I guess that it may have something to to with css incompatability.  try tweaking the css file.

good luck.

11/04/2013
00:36
Avatar
bogus
Member
Members
Forum Posts: 3
Member Since:
27/03/2013
sp_UserOfflineSmall Offline

thanx for good work!

I've tried in Firefox, Chrome and IE. There are some problems.

1) With big textarea fields, Firefox print all, IE – the same. Chrome loses the rightmost part.

2) If width of columns is not set and field content is rather short – all OK. But, if width is set, and table body has long text fields – then header columns width is different from body. I suppose the clue is something like this:
- grid consists of several tables – e.g. one for header, one for body.

- long text fields adjust width accordinng to text size

So, may be some kind of solution is to copy header cells with width attributes to the body table and remove the header table. This way – the header and the body columns will be the same width.

I put this:
var t1=$('#prt-container thead'); 

$('#prt-container tbody').before(t1.clone());

 t1.remove();  

And it fixes my table.

I don't know, if is possible with subgrids… 

28/05/2013
23:10
Avatar
NewHistoricForm
New Member
Members
Forum Posts: 1
Member Since:
08/05/2013
sp_UserOfflineSmall Offline

This is exactly what I'm looking for. Only that I can get it to work. I keep getting an error: 

TypeError: $.browser is undefined
[Image Can Not Be Found]
if ($.browser.opera || (/chrome/.test(navigator.userAgent.toLowerCase())))

I think that I didn't correctly insert the setPrintGrid function correctly as I just created printGrid. js file and inserted there. But i have no idea what a "global namespace" is. Here is my code:

     <script src="js/printgrid.js" type="text/javascript"></script>

<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
 <script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>

   <script src="js/jquery.printelement.js" type="text/javascript"></script>
<script type="text/javascript">        

$(function(){
  $("#list").jqGrid({
    url:'request.php',
    editurl: "jqGridCrud.php",
    datatype: 'xml',
    mtype: 'GET',
    multiselect:true,
    multiboxonly:true,
    height: 530,
    width: 850,
    
    colNames:['id','Project', 'Assigned To','Assign Date','Check Date','Due Date','Attachments'],
    colModel :[
      {name:'id', index:'id', width:25},
      {name:'name', index:'name', width:250, align:'left',editable:true, editoptions:{
            size:60} },
      {name:'id_continent', index:'id_continent', width:55, align:'right',editable:true,edittype:'select',
      editoptions:{value: "Henry:Henry; Ramon:Ramon; Paul:Paul" },mtype:'POST'  },
     
      {name:'lastvisit', index:'lastvisit', width:70, align:'right',formatter: 'date',srcformat:'mm-dd-yyyy',newformat: 'mm-dd-yyyy',editable:true, edittype: 'text',mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'mm-dd-yyyy'});}}} ,
      
      
      {name:'cdate', index:'cdate', width:70, align:'right',formatter: 'date',srcformat:'mm-dd-yyyy',newformat: 'mm-dd-yyyy', edittype: 'text',editable:true ,mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'mm-dd-yyyy'});}}} ,
    
      {name:'ddate', index:'ddate', width:70, align:'right',formatter: 'date',srcformat:'mm-dd-yyyy',newformat: 'mm-dd-yyyy',editable:true, edittype: 'text',editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'mm-dd-yyyy'});}}} ,
      
      
      {name:'email', index:'email', width:70,align:'center',sortable:false,mtype:'POST', formatter: 'link' }
    ],
    pager: '#pager',
    
    rowNum:20,
    rowList:[20,40,80],
    sortname: 'id',
    sortorder: 'desc',
    viewrecords: true,
    gridview: true,
    caption: 'Pending Assignments',
    
 ondblClickRow: function(rowid) {
    
    $(this).jqGrid('editGridRow', rowid,
                        {width:450,Height:400,recreateForm:true,closeAfterEdit:true,
                         closeOnEscape:true,reloadAfterSubmit:false, modal:true,mtype:'post'});}
                        
                        
            });
    

 $("#list").jqGrid("navGrid", "#pager", { add: false, search: false });
 
    

    // setup grid print capability. Add print button to navigation bar and bind to click.
    setPrintGrid('list','pager','Print');

    });
</script>

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
33 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