带有附加输入值参数的Jqgrid问题

时间:2013-01-20 22:07:18

标签: jquery jqgrid

我有一个javascript函数,用于构建应用程序的用户界面。

首先,我在div中追加所有需要的元素,其中一个是jqgrid。

以下是一个例子:

    //Generate the controls
    var c = '';
        c += '<table>';
        c += '<tr>';
        c += '<td><label for="from_date">Start Date</label><td>';
        c += '<td><input type="text" id="from_date"/></td>';
        c += '<td><label for="to_date">End Date</label><td>';
        c += '<td><input type="text" id="to_date"/></td>';              
        c += '</tr>';
        c += '</table>';

    //Perform an ajax call update date pickers
    $.ajax({
        url: "php/daily_schedule/daily.schedule.get.date.limits.php",
        dataType: "json",
        success: function(data) {

        //Update the values of the inputs
        $("#from_date").val(data.MAX);
        $("#to_date").val(data.MAX);

        //Split json results to pass new date objects
        var max_array = data.MAX.split('-');

        var max_yy    = max_array[0];
        var max_mm    = max_array[1]-1;
        var max_dd    = max_array[2];

        var min_array = data.MIN.split('-');

        var min_yy    = min_array[0];
        var min_mm    = min_array[1]-1;
        var min_dd    = min_array[2];

        //Initiate the from date picker
        $( "#from_date" ).datepicker({
                        dateFormat :"yy-mm-dd",
                        defaultDate: new Date(max_yy, max_mm, max_dd),
                        maxDate: new Date(max_yy, max_mm, max_dd),
                        minDate: new Date(min_yy, min_mm, min_dd),                                                                                                           
                        changeMonth: false,
                        numberOfMonths: 1,
                        onClose: function( selectedDate ) {
                                        $( "#to_date" ).datepicker( "option", "minDate", selectedDate );
                        },
                        onSelect:function(){

                            load_FLT();

                        }

        });

        //Initiate the to date picker                                                       
        $( "#to_date" ).datepicker({
                        dateFormat :"yy-mm-dd",
                        defaultDate: new Date(max_yy, max_mm, max_dd),
                        maxDate: new Date(max_yy, max_mm, max_dd),
                        minDate: new Date(min_yy, min_mm, min_dd),                                                                                                                              
                        changeMonth: false,
                        numberOfMonths: 1,
                        onClose: function( selectedDate ) {
                                        $( "#from_date" ).datepicker( "option", "maxDate", selectedDate );
                        },
                        onSelect:function(){

                            load_FLT();

                        }

        });         

        }

    });


    //Append the controls
    $('#daily_schedule_core_filters_container').append(c)

    //Generate grid elements
    $('#daily_schedule_core_grid_container').append('<table id="daily_schedule_grid"></table>')
    $('#daily_schedule_core_grid_container').append('<table id="daily_schedule_grid_pager"></table>')

然后我添加网格:

    //Create the daily schedule grid
    jQuery("#daily_schedule_grid").jqGrid({
        url:'php/daily_schedule/daily.schedule.grid.php',
        datatype: "json",
        hidegrid: false,

等 等等 等

我的问题是我将其添加到我的网格中:

        postData: {
            df: function() { return $('#from_date').val()},
            dt: function() { return $('#to_date').val()}
        },
        mtype: 'POST',

并且它继续将POST作为未定义的值发送。

关于我做错的任何想法?

1 个答案:

答案 0 :(得分:0)

通过在ajax调用上应用.done()并在done内部创建网格来解决问题。 不管怎样,谢谢!