0

I have a column in a jqgrid defined as number. The user is forced to enter a number like 6.5 with the comma delimeter being a point. This grid is also used by german speaking people who are used to insert numbers like this 6,5 using the comma as the delimeter.

This people are getting upset when they are not allowed to insert 6,5 instead of 6.5 :D

To make their (and in the end) my life more convenient I'm looking for a way to convert automatically the 6,5 to 6.5 . This should be done on the client side, since I want to rely on jqgrid num checking.

Thus I should check (and maybe transform) the number before jqgrid is checking it. Is this possible?

--edit--

None of these functions are called, except the first one. Any idea why this could be the reason?

    afterInsertRow:function (rowid, aData){
                alert('fire');

            },
    beforeSaveCell : function(rowid,celname,value,iRow,iCol){ 
                alert('no fire');
                return "new value";

        },
    beforeSubmitCell : function(rowid,celname,value,iRow,iCol){ 
                alert('no fire2');
                return "new value";

        },
    beforeEditCell : function(rowid,celname,value,iRow,iCol){ 
                alert('no fire3');
                return "new value";

        },

--edit2--

This is the code I'm using for inline editing.

onSelectRow: function(row_id){  
if(row_id != null) {
    var date_str = jQuery('#grid').getCell(row_id, 'date_str');
    //var sum = jQuery('#grid').getCell(row_id, 'sum');
    var description = jQuery('#grid').getCell(row_id, 'description');
    if(date_str != "Total"){
        if(row_id !== last_selected_row) {
            if(row_id == -99){
                //thats the first click of the user after initial load of the grid
                jQuery('#grid').jqGrid('saveRow',row_id)
                    .editRow(row_id, true,true,reload);
                last_selected_row = row_id;
                        }
            else{
              //after user jumps from one cell to another using the mouse
              jQuery('#grid').jqGrid('saveRow',last_selected_row,reload);
              jQuery('#grid').jqGrid('restoreRow',last_selected_row);
              last_selected_row = row_id;
            }
        } else {
            jQuery('#grid').jqGrid('saveRow',row_id)
                .editRow(row_id, true,true,reload);
            last_selected_row=row_id;
                    }
            }
        }

},

Thomas Kremmel
  • 14,575
  • 26
  • 108
  • 177
  • Could you clear **where** the user enter a number? Do you mean searching (which one), form/inline/cell edditing, add new row or something else? – Oleg Dec 09 '10 at 16:20
  • when a user is entering a number in a cell. -> thus cell editing – Thomas Kremmel Dec 09 '10 at 16:31

1 Answers1

1

If you use cell editing, you can try to write your beforeSaveCell event handler which do the text replacement which you need.

UPDATED: I don't know which information can be placed in the cell, but probably the usage of Masked Input Plugin (see old answer here) or just 'keypress' filtering (see another answer) could improve user experience.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, I think this is what I was looking for. But for some reason this event does not fire. See the snippet that I inserted in my question on how I used the method. – Thomas Kremmel Dec 09 '10 at 20:35
  • @Tom Tom: You posted only small code fragments, but it is not clear whether you use the functions in the correct place and whether you use other important jqGrid settings. So if some code not work you should post **full** code which can be used to reproduce the problem. Then I or somebody else could reproduce the problem and fix it. – Oleg Dec 09 '10 at 20:44
  • http://pastebin.com/9ayXw1v5 .. You are right. I created a pastebin with the complete code, since it is so long.. – Thomas Kremmel Dec 09 '10 at 21:07
  • 1
    @Tom Tom: At first sight blick one can see that you don't use cell editing (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:cell_editing) like you wrote, because you don't define `cellEdit:true`. So `cellsubmit:'remote'` and all cell editing events like `beforeSaveCell` event will **not work**. You try to implement inline editing (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing) because you use `editRow`, `editRow` and `restoreRow` functions. Moreover the usage of `afterInsertRow` and many `setCell` makes your code work very slow. – Oleg Dec 09 '10 at 21:17
  • yes you are right. sorry I'm pretty new to jqgrid and did not knew the difference. BeforeEditCell would fire now, but I want to stick with inline editing. Do you have an idea how to achieve the task I want to? I think I have to somehow call a function between saveRow and editRow.. – Thomas Kremmel Dec 09 '10 at 21:32
  • 1
    @Tom Tom: I personally also prefer inline editing to edit the data and form editing to add new row or delete the existing one. In the situaltion with '.' and ',' I would be on your place to use `dataEvents` technique with 'keypress' or 'change' event handle (see http://stackoverflow.com/questions/4192768/on-key-down-restrict-the-user-to-enter-some-special-characters/4198475#4198475). It it **common way** for all kind of editing (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#editoptions) and will try to replace ',' to '.' **immediately** after the user it press. – Oleg Dec 09 '10 at 21:46
  • ok thank you. now it is much more clear.. anyway, still stuck with getting the inserted data. tried it with var v=$(e.target).val(); but this does not return the inserted data.. hmm.. ok.. it's late.. maybe tomorrow I find a solution ;-) thanks a lot for your help! – Thomas Kremmel Dec 09 '10 at 22:50