5

We use a custom formatter to output html form text boxes. In the case that a user has entered in data and they hit the next/prev button, we want to tell them "you've edited data, hit ok to stay on this page and save your data". How can you do this?

The 'onPaging' event fires when you use the pager but it doesn't seem to let you prevent the pagination from occuring.


Update: Current workaround:

var currPg = 1;
var dirty = 'false';


  $("#list").jqGrid({
    ...
    onPaging: function (b) {
        var nextPg = $("#list").getGridParam("page");

        if (dirty == 'false') {
           currPg = nextPg;
           return;
        }


        $( "#dialog-confirm" ).dialog({
        modal: true,
        buttons: {
            "Stay on current page": function() {
                $( this ).dialog( "close" );
            },
            "Change page": function() {
                $( this ).dialog( "close" );
                reloadGrid($("#list"), null, nextPg, 'false');
            }
        }
        });

        $("#list").setGridParam({page:currPg}); //Workaround - jqGrid still increments the page num even when we return stop so we have to reset it (and track the current page num)    
        return 'stop';
    },

Update 2: Bug logged here.

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

2 Answers2

5

If the function onPaging returns 'stop' then the pagination will be stopped.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg, working on this now. One bug I think I've found is that if you return 'stop' the grid page number is still incremented.. will submit a bug.. – Marcus Leon Sep 27 '10 at 18:10
  • @Marcus: As a workaround you can reset the value with `setGridParam` – Oleg Sep 27 '10 at 18:12
  • Just did that :) Is there a way to determine the currently displayed page? If you use `getGridParam('page')` it returns the page which will be displayed next. I used a new variable to keep track of the actual page number being displayed - not sure if there is a better way.. – Marcus Leon Sep 27 '10 at 18:20
  • @Marcus: You can get it with respect of jQuery directly. – Oleg Sep 27 '10 at 18:30
  • I'm not clear what you're referring to - how can you query jqGrid to get the current page being displayed? If you use getGridParam('page') in onPaging this will return you the next/prev/first/last page number - not the current page number. – Marcus Leon Sep 27 '10 at 18:42
  • @Marcus: You can use `$('input.ui-pg-input',$('#pager')[0]).val()` to get and `$('input.ui-pg-input',$('#pager')[0]).val(str)` to set and str to the pager. – Oleg Sep 27 '10 at 19:41
  • There is one case where it appears that does not work - if you type into the pager text box the page number you want to go to and hit enter - the code you mention will return the next page, not the current page. – Marcus Leon Sep 27 '10 at 20:16
  • @Marcus: I can not reproduce your problem. Look at http://www.ok-soft-gmbh.com/jqGrid/Pager.htm demo. You can type anything in pager and click "get" button. You will see text from the pager in the alert message box. You can also type in the input box anything and click "set" button. All work like I imagine it. I see no problem. – Oleg Sep 27 '10 at 20:32
  • If I'm on page 10 and I type "20" and hit enter into the pager, in the onPaging function I want to be able to determine that we are (currently) on page 10 - but `$('input.ui-pg-input',$('#pager')[0]).val()` will return "20", not "10". Your example is a little different than my use case (you're not using onPaging). Make sense? Thx for your help Oleg.. – Marcus Leon Sep 27 '10 at 20:37
  • @Marcus: The workaround is very easy look at new version of http://www.ok-soft-gmbh.com/jqGrid/Pager.htm and repeat your experiment. But the small bug in jqGrid I found: the lines 1740 and 1741 from grid.base.js should be swaped. Currently one change the value of `pager` parameter **before** calling of `onPaging` event handlr. – Oleg Sep 27 '10 at 21:11
  • Thanks Oleg. I was doing something similar - I put my current implementation/workaround in the post - what do you think? – Marcus Leon Sep 27 '10 at 21:18
  • @Marcus: Your implementation has one problem: the first initialisation of `currPg`. You set it to 1 which is in 99,9% correct, but use unclear string `dirty` (which can be boolean). I set the velus in `gridComplete` which will be called after setting of the first value of pager. Nevertheless your workaround will aslo work. You should only remove `dirty` variable and just use `currPg=1` – Oleg Sep 27 '10 at 21:33
0

As per my observation onPaging event works well in latest jqgrid plugin.While if we use previous jqgrid plugin ( before 3.8 version).onPaging event will work but,there is bug in pagination after we use this event.As it automatically increment value of page either user click on ok or cancel(in both cases).Which lead to corrupt data of paggination.

Innovation
  • 1,514
  • 17
  • 32