【问题标题】:How to sort table returned in AJAX call如何对 AJAX 调用中返回的表进行排序
【发布时间】:2018-03-11 05:58:09
【问题描述】:

我对 PHP 页面进行了以下 AJAX 调用,以从数据库中获取数据以将其显示在 HTML 页面的表中。我希望 #OrderTable 可以排序。

$.ajax({
  type: "POST",
  url: "searchorders.php",
  data: {
    'OrderBy': OrderBy,
    'StartDate': startDate,
    'EndDate': endDate
  },
  success: function(data) {
    if (data == "Failed") {
      $('#NoData').append("No data Found!");
    } else {
      $('#OrderTable').append(data);
      document.getElementById("Results").style.display = 'block';
      **$('#SearchResults').DataTable();**
    }
  }
})

我在 PHP 页面中的部分表格

$output.='<hr />
    <table id="SearchResults" class="table table-striped table-bordered" style="width:auto;">
    <thead>
    <tr>
        <th>Order No.</th>
        <th>Customer Name</th>
        <th>Order Date</th>
        <th>Category Name</th>
        <th>Category Type</th>
        <th>Quantity in Kilos</th>
        <th>Delivery Date</th>
        <th>Order Status</th>
    </tr>
    </thead>
    ';

【问题讨论】:

  • 获取记录排序并将返回的记录显示到表中
  • 在你的order by 中使用SQL 接收到的所有数据都会被排序。
  • 我需要用户根据自己选择的实时时间列进行排序
  • 查看数据表datatables.net
  • @DimitrisFilippou,我用过它,但它只显示箭头而没有排序,如果你能帮助我或者你以前用过它

标签: php jquery ajax sorting


【解决方案1】:

在您的 sql 代码本身(即 searchorder.php 本身)中使用 order by query,然后显示从那里返回的数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2021-10-21
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多