0

I want to get data from remote database with ajax call. My search criterias are minimum date, maximum date, selectable types and I have a search button. My problem is; when I click search button, system works correctly but if I change the search criterias and click search button again, I am getting my first click's results. What should I do at this situation?

Thank you so much.

$('#openDialog').dialog({height:400, width:545, autoOpen:false});
$('#objectTypeSelected').selectable();
$('#searchBtnObjects').click(function (evt) {
 searchBtnObjectsClick();
});

function searchBtnObjects() {

    var types = [];
    var begin = $("#minDate").val();
    var end = $("#maxDate").val();

    var selectedTypes = $(".ui-selected");
    var typeString ="";
    for (var i = 0; i < selectedTypes.length; i++) {
        types[i] = $(".ui-selected")[i].id;
        typeString=typeString+$(".ui-selected")[i].id+",";
    }
    if (objectsTable != null) {
        var postData = {
            ajaxRequest:document.helper.getPageName(),
            directAjaxMode:true,
            types:typeString,
            begin:begin,
            end:end}
        objectsTable.jqGrid("setGridParam", {postData:postData});
        objectsTable.trigger('reloadGrid');
    }
    else{
        objectsTable = $('#objectList').jqGrid({
                datatype:'json',
                colModel:[
                    {name:"ID", label:messageDictionary["ID"], editable:false, formatter:cc_formatter, unformat:cc_unformatter, index:"ID"},
                    {name:"DATE", label:messageDictionary["DATE"], editable:false, formatter:'date', formatoptions:{srcformat:'d/m/Y H:i:s', newformat:'d/m/Y H:i:s'}, index:"DATE"}
                ],
                mtype:'POST',
                multiselect:true,
                pager:'#objectsPager',
                postData:{
                    ajaxRequest:document.helper.getPageName(),
                    directAjaxMode:true,
                    types:typeString,
                    begin:begin,
                    end:en},
                url:'search/getObjects',
                jsonReader:{ repeatitems:false, cell:"", id:"id", userdata:"jsonModel", root:"rows" },
                ignoreCase:true,
                height:80,
                autowidth: true,
                shrinkToFit:true,
                sortname:'ID',
                sortorder:"asc",
                loadonce:true,
                rowNum:30,
                rowList:[30, 50, 100],
                rownumbers:true,
                viewrecords:true
            }
        );
 }
}
S.Balaban
  • 174
  • 2
  • 19

2 Answers2

0

You have to clear fields as soon as you get search results like below.

$("form").trigger("reset");

Refer : clearing-my-form-inputs-after-submission

Alien
  • 15,141
  • 6
  • 37
  • 57
0

The problem you have is the parameter in jqGrid settings

loadonce: true

This setting automatically set the datatype to local after the first creation of the grid.

In order to have continued request to the server you will need to remove this setting or set it to false

loadonce : false;

More on jqGrid parameters you can see in our new documentation here

Tony Tomov
  • 3,122
  • 1
  • 11
  • 18