0

我正在使用 jqxgrid,我有下面的代码片段,我想在单击调用 Ajax 方法的按钮上显示加载指示器,并将其隐藏在成功方法上或以其他方式显示它,因为我需要从发出的时间请求中显示加载指示器直到我得到数据

      $("#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);
                 }
                 });
             };

//源对象格式化数据 function SetSearchFields(fieldName, source) {

                  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

         };
4

1 回答 1

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);

        },
       ...

此致,

阿尔佩什

于 2014-03-01T05:31:23.883 回答