2

I have a grid with a pager. I need to stop the pager from loading another page while on the current page a row is in inline edit. So when i create the grid i define the onPaging function

....
onPaging : function(){
        if (inEdit()>0){
            alert("Finish editing the current line");
            return 'stop';
        }
    }
....

the function inEdit simply counts how many lines have the attr editable.

This does the job, however later when i call the restoreRow function on the row that was in edit when the paging was stoped the function fails to restore the row to the previous state.

Later Edit:

The problem occurs later when this function is called to cancel the edit

function cancelEdit(id){
    /*this line does nothing at all --> */ $('#list').jqGrid('restoreRow',id);
    //The only way restore worked is by calling a grid reload but that is not really a solution
    $('#list').trigger("reloadGrid", [{page:$('#list')[0].p.page}]);
    $('#'+id+' [name=editButton]').show();
    $('#'+id+' [name=submitButton]').hide();
    $('#'+id+' [name=cancelButton]').hide();
}

PS: The Edit/Save/Cancel/Delete are custom buttons

cosmin.danisor
  • 943
  • 1
  • 12
  • 29
  • Are you feeding data to your grid from a server? Is the use case on this where someone else is editing data that is being displayed in your grid? – Mark Mar 08 '13 at 14:36
  • For now, the data is loaded locally, the problem is not with someone else editing the data, but in the grid you must be able to edit only 1 line at a time and only be able to stop the editing by saving or canceling (with confirmation) all other functions of the grid, that may interrupt editing, such as pagination must be stopped until edit is finished. – cosmin.danisor Mar 08 '13 at 15:40
  • Has you solved it? – Hong Van Vit Mar 15 '18 at 03:25

1 Answers1

0

I think if you look at doing what you are doing but checking out Oleg's post at jqGrid - Inline edit - Detect dirty / changed cells and using that flag to prevent paging you will be able to accomplish what you are trying to do.

Community
  • 1
  • 1
Mark
  • 3,123
  • 4
  • 20
  • 31
  • I'm doing exactly that, the inEdit method returns the number of $('tr[editable=1]'). My problem is not with stopping the pagination it stops but later when i call restoreRow it doesn't work. I will add the code so you see what I'm walking about – cosmin.danisor Mar 08 '13 at 17:37
  • User choice ... that method gets called when cancel button is pressed. There is a combination of stuff that makes the restoreRow method to stop working, example: press edit button -> starts inline editing -> press next page button -> the onPaging function stops the next page from loading and brings on an alert-> press cancel button -> calls cancelEdit method that tries to restore the row ... but that doesn't work anymore, if you don't press the pagination buttons while editing the cancel button works flawlessly – cosmin.danisor Mar 08 '13 at 18:43
  • So if I understand this, if they hit the pagination button while editing they get an alert confirmation window, and if they choose to continue you want to discard their edit and change page? – Mark Mar 08 '13 at 19:27
  • actually if they hit the pagination button they get an alert telling them to finish editing before moving to another page, but later if they hit the cancel button (button that calls the method written above) the restoreRow line does nothing doesn't throw an exception is like it's not there – cosmin.danisor Mar 08 '13 at 19:32
  • So even after the cancel button is hit the `if (inEdit()>0){` is still showing that their is a line in edit ? – Mark Mar 08 '13 at 19:33
  • yes, I checked it with debugger, after restoreRow is called on the correct row (the buttons on the line change as if the editing has stopped), cells are still in edit mode and the editable=1 attr is still on the tr – cosmin.danisor Mar 08 '13 at 19:36
  • I did a mockup in jsFiddle and I get the same results, the value is set even after hitting the cancel button, or running the function. If you look at the `$("#grid tr[editable]")` object, it does change values on what is actually being edited. If you want to parse out that object I think it will get you where you want to be, but I don't have the time to mock it out for you. – Mark Mar 08 '13 at 20:42