0

The problem is that i have made a function that gives back a value for bottominfo.

var bottominfo = function (){
        var vMonth = document.getElementById('cmb_Month').value;
                    var vYear = document.getElementById('Year').value;
                    var StartDate = firstdayofmonth(vMonth, vYear);
                    var EndDate = lastdayofmonth(vMonth, vYear);            
                    var next=getnext(StartDate,EndDate);
                    var bottominfo='You are going to add'+next;

                    alert(bottominfo);
                    return bottominfo;
                };

But the function is only called when first load the grid and not every time that i open a form. Is there a way to change bottominfo every time i open a form?

UPDATED 3: I have that method:

  jQuery(list).jqGrid('navGrid',pager,{edit:true},
                {
                            width:colwidth*1.05,
                            height:"auto",
                            reloadAfterSubmit:true,
                            closeAfterAdd: true,
                            recreateForm: true,
                            drag: false,
                            onClose: after,
            bottominfo: bottominfo()});

Is there a problem with the way i call the function?

UPDATED 2

The other properties are not really helpfull for me, so i erased them. The other code is :

 function firstdayofmonth(vMonth, vYear){
return vYear+'-'+vMonth+'-01';
}

 function lastdayofmonth(vMonth, vYear){
var myDate=new Date();
var vMonth=parseInt(vMonth)+2;
var vYear=parseInt(vYear);
if (vMonth>12)
{vYear=vYear+1;
vMonth=vMonth-12;}
myDate.setFullYear(vYear, vMonth, 0);
return myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+myDate.getDate();
}

var nextprogram=0;


function getnext(StartDate,EndDate) {

next="Applications between"+StartDate+"and"+EndDate;
return next;
}
ilektrologaki
  • 95
  • 1
  • 1
  • 8

1 Answers1

0

Probably you should just use recreateForm: true property as additional option of "Add" and "Edit" settings (see here an example). I personally change $.jgrid.edit to use recreateForm: true as default in all projects which I made for the customers.

Additionally you should replace one ; in your code to , because currently bottominfo variable are undefined and have to be interpreted as global. Some browsers will stop executing of the code in strict mode and interpret the case as an error. So just replace

var next=getnext(StartDate,EndDate);
    bottominfo='You are going to add'+next;

to

var next=getnext(StartDate,EndDate),
    bottominfo='You are going to add'+next;

UPDATED: You use bottominfo: bottominfo() as parameter of navGrid method. So the value for the will be set only once during the call. To be able to have dynamical bottominfo I can suggest you two ways:

1) You can first call navGrid with add:false, edit:false options and then use navButtonAdd to add custom buttons which looks like the original "Add" and "Edit" buttons. Inside of the onClickButton callback you will get the rowid of currently selected row (get selrow parameter with respect of getGridParam) and then call editGridRow with all parameters which you need.

2) Alternatively you can set any dummy string as bottominfo and overwrite it manually to another text manually. The code can be like the following

$.extend($.jgrid.edit, {
    bottominfo: "dummy text",
    recreateForm: true,
    beforeShowForm: function ($form) {
        var $bottomInfo = $form.parent().find("table.EditTable td.bottominfo");
        $bottomInfo.html('<span style="color:red">Now: ' + new Date() + '</span>');
    }
});

see the demo:

enter image description here

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @ilektrologaki: You should post *more full* code which can be used to reproduce your problem. The list of options which you use somewhere don't really help to understand and clear the problem which you have. For example the method `bottominfo` can be called *only* one during the executing of *the statement* which you use. – Oleg Mar 14 '12 at 09:20
  • I posted more code. Do you need something else for recreating the problem?Why the method bottominfo is called only once? When recreating the form shouldn't the statement: bottominfo: bottominfo () call every time the function? – ilektrologaki Mar 14 '12 at 09:39
  • The code if **not full**. You have problem with `bottominfo` property of `editGridRow` method. So it's important to see the code which shows **how you call `editGridRow` method**: directly or indirectly. For example if you call `editGridRow` method directly inside of `ondblClickRow` callback for example, the value of `bottominfo` property will be filled every time. If you on the other time use `navGrid` **once** and use `bottominfo` property as an option the `bottominfo` property will be calculated **once** at the call of `navGrid`. – Oleg Mar 14 '12 at 09:48
  • I am sorry. I did not understand that the way i call editGridRow is that matters. So, i do have navgrid and i need bottominfo to change every time i open the form – ilektrologaki Mar 14 '12 at 09:52
  • I think you are just amazing! Waw! Thanks a lot. I used the second suggestion. – ilektrologaki Mar 14 '12 at 11:55