2014-01-15 53 views
0

我正在使用jqxgrid,我有下面的代碼片段,我想顯示負載指示器上的按鈕點擊調用Ajax方法,並將其隱藏在成功方法或反正其他顯示它作爲我需要從取得的時間請求顯示負載指示符直到我的數據得到jqxgrid不顯示繁忙或加載指示器

 $("#btnSearch").bind('click', function() { 

    //show indicator here 
    LoadLookUpSearchGrid(); 
    } 


    //Ajax call to fetch data 
    function LoadLookUpSearchGrid() { 
       var filterRows = getGridRows(); 
       $.ajax({ 
       type: 'POST', 
       dataType: 'json', 
       async: false, 
       cache: false, 
       url: 'AddEditView.aspx/LoadLookUpSearchGrid', 
       data: JSON.stringify({ FilterType: $('select#ddlFilterType').val() , Id: $("#txtId").val() , Name: $("#txtName").val(), SearchText: '', FilterRows: filterGridRows}), 
       contentType: 'application/json; charset=utf-8', 
       success: function (data) { 

        var source = data.d; 
       SetSearchFields($('select#ddlFilterType option:selected').text(), source); 

       }, 
       error: function (err) { 
        alert(err.text + " : " + err.status); 
       } 
       }); 
      }; 

//源對象到格式數據 功能SetSearchFields(fieldName的,源){

    var columns; 

       if (fieldName == "Operating Company") { 

          source = 
          { 
           datatype: "xml", 
           datafields: [ 
            { name: 'COMPANY', type: 'string' }, 
            { name: 'DESCR', type: 'string' } 
            ], 
           async: false, 
           root: "Company", 
           localdata: source 
          }; 
        columns = [ 
          { text: 'OPCO ID', dataField: 'COMPANY', width: '30%' }, 
          { text: 'Company Name', dataField: 'DESCR', width: '65%' } 
           ]; 

       } 

    lookupSearchResultGrid(source, columns,fieldName); 
    } 

//adaptor to fill source and bind grid 
    function lookupSearchResultGrid(source, columns,fieldName) { 

       var searchViewGridDataAdapter = new $.jqx.dataAdapter(source); 

       $("#divLookupSearch").jqxGrid(
         { 
          width: '100%', 
          source: searchViewGridDataAdapter, 
         theme: theme, 
         sortable: true, 
         pageable: true, 
         autoheight: true, 
         selectionmode: 'checkbox', 
         columns: columns 
        }); 
//hide indicator here on on success method of ajax call 

     }; 

回答

0

論的點擊按鈕調用showloadelement和在Ajax調用成功回調函數中調用hideloadelement。

 $("#btnSearch").bind('click', function() { 
     $('#divLookupSearch').jqxGrid('showloadelement'); 
     //show indicator here 
     LoadLookUpSearchGrid(); 
     } 
     ... 
     success: function (data) { 
      $('#jqxGrid').jqxGrid('hideloadelement'); 
      var source = data.d; 
      SetSearchFields($('select#ddlFilterType option:selected').text(), source); 

     }, 
     ... 

最好的問候,

Alpesh