「go」ボタンをクリックしたときの変数の値に従ってjsonデータが設定された動的htmlテーブルを作成しました。検索は、初めてデータが入力されたときに正常に動作しますが、実行時に変数を変更した後、テーブルに「go」ボタンをクリックして別の値をクリックすると、テーブルから特定の値を検索しようとすると、前回作成したデータから検索を試みてください。つまり、最初にデータが入力されたデータではなく、そのデータでもテーブルが変更されます。テーブルのデータを変更しても、テーブルの値は変更されますが、テーブルから値を検索するとすぐに検索されますテーブルの最初の値が入力され、その値でテーブルが変更されます。 動的に作成されたテーブルからJSONデータを検索する
\t $(document).ready(function() {
\t \t $("#report").hide();
\t \t $("#orderGraph").hide();
\t \t $("#profitGraph").hide();
\t \t $("#go").click(function() {
\t \t \t \t $("#orderGraph").show();
\t \t \t \t $("#profitGraph").show();
\t \t \t \t loadGraphOrderFilter();
\t \t \t \t loadGraphProfitFilter();
\t \t \t \t $("#report").show();
\t \t \t \t $("#datatable > tbody > tr").remove();
\t \t \t var e;
\t \t \t multicompanyUseCaseData="";
\t \t \t orderConditionData="";
\t \t \t orderTypeData="";
\t \t \t if(document.getElementById("mcuc_selection"))
\t \t \t {
\t \t \t \t e=document.getElementById("mcuc_selection");
\t \t \t \t multicompanyUseCaseData = e.options[e.selectedIndex].text;
\t \t \t }
\t \t \t if(document.getElementById("oc_selection"))
\t \t \t { \t \t \t
\t \t \t \t e = document.getElementById("oc_selection");
\t \t \t \t orderConditionData = e.options[e.selectedIndex].text;
\t \t \t }
\t \t \t if(document.getElementById("ot_selection"))
\t \t \t {
\t \t \t \t e = document.getElementById("ot_selection");
\t \t \t \t orderTypeData = e.options[e.selectedIndex].text;
\t \t \t } \t
\t \t \t var responseObj = $.parseJSON(response1);
$.each(responseObj, function (i, item) {
\t if(item.useCase == multicompanyUseCaseData || item.orderCondition == orderConditionData || item.orderType == orderTypeData)
\t {
$('<tr>').append(
$('<td>').text(item.orderId),
$('<td>').text(item.purchaseId),
$('<td>').text(item.shipmentId),
$('<td>').text(item.useCase),
$('<td>').text(item.orderCondition),
$('<td>').text(item.orderType)).appendTo('#datatable');
\t }
});
// this line performs the searching operation from the table
$('#datatable').dataTable(); \t \t
});
\t });
var response1 = '[{"orderId":"19", "purchaseId":"Alon", "shipmentId":"5", "useCase":"AGS", "orderCondition":"2", "orderType":"Customer" }';
response1 += ',{"orderId":"19", "purchaseId":"Alon", "shipmentId":"5", "useCase":"AGL", "orderCondition":"2", "orderType":"Customer" }';
response1 += ',{"orderId":"19", "purchaseId":"Alon", "shipmentId":"5", "useCase":"NAFN", "orderCondition":"2", "orderType":"Customer" }]';
<div class="x_content">
<table id="datatable" class="table table-striped table-bordered">
<thead>
\t \t \t \t \t <tr>
\t \t \t \t \t \t <th>Order Id</th>
\t \t \t \t \t \t <th>Shipment Id</th>
\t \t \t \t \t \t <th>Purchase Id</th>
\t \t \t \t \t \t <th>Use Case</th>
\t \t \t \t \t \t <th>Order Condition</th>
\t \t \t \t \t \t <th>Order Type</th>
\t \t \t \t \t </tr>
\t \t \t \t \t \t </thead>
<tbody>
</tbody>
</table>
</div>
。
こんにちは@Jimは、おそらく私はその動作していない、もう少し助けが必要:
はすでにここに答えているもう一つの例があります。 –
テーブルが変更されていますが、検索を適用するとすぐにテーブルの最初のデータが検索され、テーブルが変更されます。 –
追加したコードは、最初は不完全です。表のデータを置き換えたコードを、私が掲示したリンクの例に置き換える必要があります。 – Jim