2014-11-07 2 views
0

jTable에서 페이징을 사용하는 방법 PHP를 사용 하시겠습니까? 나는 내가 $ _REQUEST를 변경하면 문제가 여기PHP의 페이지 매김 jTable

$result = mysql_query("SELECT * FROM employee ORDER BY '" . $_REQUEST["jtSorting"] . "' LIMIT '" . $_REQUEST["jtStartIndex"] . "','" . $_REQUEST["jtPageSize"] . "';"); 

을에 [ "jtSorting"] = rowname, $ _REQUEST [ "jtStartIndex"실감 그런

<script src="jtable.2.4.0/jquery.jtable.min.js" type="text/javascript"></script> 

    //Get record count 
    $result = mysql_query("SELECT COUNT(*) AS RecordCount FROM employee;"); 
    $row = mysql_fetch_array($result); 
    $recordCount = $row['RecordCount']; 

    //Get records from database 
    $result = mysql_query("SELECT * FROM employee ORDER BY '" . $_REQUEST["jtSorting"] . "' LIMIT '" . $_REQUEST["jtStartIndex"] . "','" . $_REQUEST["jtPageSize"] . "';"); 

    //Add all records to an array 
    $rows = array(); 
    while($row = mysql_fetch_array($result)) 
    { 
     $rows[] = $row; 
    } 

    //Return result to jTable 
    $jTableResult = array(); 
    $jTableResult['Result'] = "OK"; 
    $jTableResult['TotalRecordCount'] = $recordCount; 
    $jTableResult['Records'] = $rows; 
    print json_encode($jTableResult); 

employeeTable.php

에 아래 코드를 ] = 숫자, $ _REQUEST [ "jtPageSize"] = 숫자, 작동합니다. 하지만 변경하지 않으면 '서버와 통신하는 동안 오류가 발생했습니다'라는 메시지가 표시됩니다. 여기

는 jtSorting, jtStartIndex에 대한 라인이있을 때, 누군가가 나를 이해하는 데 도움 주실 래요 jtPageSize

/* Adds jtSorting parameter to a URL as query string. 
    *************************************************************************/ 
    _addSortingInfoToUrl: function (url) { 
     if (!this.options.sorting || this._lastSorting.length == 0) { 
      return url; 
     } 

     var sorting = []; 
     $.each(this._lastSorting, function (idx, value) { 
      sorting.push(value.fieldName + ' ' + value.sortOrder); 
     }); 

     return (url + (url.indexOf('?') < 0 ? '?' : '&') + 'jtSorting=' + sorting.join(",")); 
    }, 

    /* Overrides _createJtParamsForLoading method to add sorging parameters to jtParams object. 
    *************************************************************************/ 
    _createJtParamsForLoading: function() { 
     var jtParams = base._createJtParamsForLoading.apply(this, arguments); 

     if (this.options.sorting && this._lastSorting.length) { 
      var sorting = []; 
      $.each(this._lastSorting, function (idx, value) { 
       sorting.push(value.fieldName + ' ' + value.sortOrder); 
      }); 

      jtParams.jtSorting = sorting.join(","); 
     } 

     return jtParams; 
    } 

}); 
})(jQuery); 

jquery.jtable.min.js의 코드인가?

답변

0

나는 이것을 한 번 거쳐야한다고 생각합니다. Listaction jtable for Pagination and sorting table

데이터를 반환하려면 jQuery.Deferred가 필요합니다. 그것을 위해

listAction: function (postData, jtParams) { 
    return $.Deferred(function ($dfd) { 
     $.ajax({ 
      url: '/Employee_Controller/EmployeeList_method?jtStartIndex=' + jtParams.jtStartIndex + '&jtPageSize=' + jtParams.jtPageSize + '&jtSorting=' + jtParams.jtSorting, 
      type: 'POST', 
      dataType: 'json', 
      data: postData, 
      success: function (data) { 
       $dfd.resolve(data); 
      }, 
      error: function() { 
       $dfd.reject(); 
      } 
     }); 
    }); 
} 

수동으로 포스트 값으로

핸들을. 이게 도움이되기를 바랍니다.