views:

688

answers:

1

I have a jqGrid script like that:

jQuery(document).ready(function() {

var startDate = $("#startDate").Val();
jQuery("#sandgrid").jqGrid({
    url: "/Deposit/Search?startDate='" + startDate + "'",
    datatype: 'json',
    mtype: 'GET',
    height: 255,
    width: 700,
    colNames: ['Index', 'Name', 'Code'],
    colModel: [
         { name: 'item_id', index: 'item_id', width: 65 },
         { name: 'item', index: 'item', width: 150 },
         { name: 'item_cd', index: 'item_cd', width: 100}],

    pager: jQuery('#sandgridp'),
    rowNum: 10,
    rowList: [5, 10, 20, 50],
    sortname: 'item_id',
    sortorder: "desc",
    viewrecords: true,

    caption: 'My Grid'
});

});

In the view, there also have a input text box:

         <td>
             <% Html.jQuery().DatePicker()
                .Name("startDate")
                .Render(); %>           
        </td>

What I want to do is to pass the value from "startDate" to call jqGrid's url: "/Deposit/Search?startDate='" + startDate + "'". But it seems the data does not pass into the url. WHat is the issue? Is any other approach available for doing a searching function with jqGrid?

Thanks a lot!!

+1  A: 

Set new url and then reload grid:

jQuery("#sandgrid").jqGrid().setGridParam({url : '/Deposit/Search?startDate=' + $("#startDate").datepicker('getDate')}).trigger("reloadGrid")

LukLed
Thanks, LukLed! But it seems I cannot get the newUrl correctly. Do you have any idea where I possible am wrong in the Javascript file above?
Liang Wu
Changed some code and now it should work.
LukLed
Thanks again, LukLed! But $("#startDate").datepicker('getDate') seem to return null.
Liang Wu
I guess that is because the script called after the submit, so the field value is not retained any more.
Liang Wu
LukLed, your code is correct. Thanks! I need to use ViewData to store the value after submit.
Liang Wu
You propably wanted to restore value of #startDate after post so yes, you have to put it back in model (ViewData) and set value in view. I am glad I helped:)
LukLed