views:

93

answers:

1

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';
    },
+1  A: 

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

Oleg
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
@Marcus: As a workaround you can reset the value with `setGridParam`
Oleg
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
@Marcus: You can get it with respect of jQuery directly.
Oleg
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
@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
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
@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
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
@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
Thanks Oleg. I was doing something similar - I put my current implementation/workaround in the post - what do you think?
Marcus
@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