2017-07-13 49 views
0

私はテーブルにデータを表示するためにjQueryブートグリッドを使用しています。 Ajaxを使用してデータを取得し、JSON形式で値を返します。 JSON文字列では、テーブルの他のセクションに表示するために読みたい変数になります。BootGridがJSONで返された値を読み取る

Ajaxの機能は以下の通りである。私はPHPのページからの応答を見ていると、それは次の形式が付属しています

function ajaxAction(action) { 
      data = $("#frm_"+action).serializeArray(); 
      $.ajax({ 
       type: "POST", 
       url: "response_pedidos.php", 
       data: data, 
       dataType: "json",  
       success: function(response) 
       { 
       $('#'+action+'_model').modal('hide'); 
       $("#employee_grid").bootgrid('reload'); 
       }, 
       error: function (request, error) { 
       console.log(arguments); 
      } 
      }); } 

:ページで

{"current":1, 
"rowCount":20, 
"total":7, 
"cantidad_totales":8.5, 
"id_pedido":13, 
"rows":[{"id_pedidos_productos" :"57", 
      "cantidad":"1.5", 
      "descripcion":"prueba con decimales", 
      "nombre":"Astro naranja"}, 
     {"id_pedidos_productos":"52", 
      "cantidad":"1", 
      "descripcion":"", 
      "nombre":"Gipso grande"}, 
     {"id_pedidos_productos":"54", 
      "cantidad":"1", 
      "descripcion":"", 
      "nombre":"Lilis Rosita"}, 
     {"id_pedidos_productos":"53", 
      "cantidad":"1", 
      "descripcion" :"", 
      "nombre":"Plumosos"}, 
     {"id_pedidos_productos":"56", 
      "cantidad":"1", 
      "descripcion":"", 
      "nombre":"ROSAS BABY VENDELA"}, 
     {"id_pedidos_productos":"55", 
      "cantidad":"1", 
      "descripcion":"", 
      "nombre":"Rosas rojas"}, 
     {"id_pedidos_productos":"51", 
      "cantidad":"2", 
      "descripcion":"", 
      "nombre":"ROSAS ROSITAS \"MATIZADAS\"" }]} 

、私のテーブルには、次のようになります私は得られた値をテーブルの下のフィールドに表示したい: enter image description here

ここで私がしたいのは、 : "cantidad_totales"

私はそれをキャッチしてページの履歴セクションに表示したいと思います。

どうすればいいですか?

答えて

1

これは、あなたがそれを扱うことができる方法です:

var cantidadTotales; 

$('#tbl').bootgrid({ 
    formatters:{ 
    ... 
    }, 
    rowCount: [5, 10, 25], 
    ... 
    labels: { 
    .... 
    }, 
    css: { 
    ... 
    }, 
     responseHandler: function (data) { 
      var response = { 
       current: data.current, 
       rowCount: data.rowCount, 
       rows: data.rows, 
       total: data.total, 
       cantidad_totales: data.cantidad_totales, 
       id_pedido: data.id_pedido 
      }; 
      //store cantidad_totales into a variable... 
      cantidadTotales = data.cantidad_totales; 

      return response; 

     }, 
     ajaxSettings: { 
      method: 'POST', 
      contentType: 'application/json' 
     }, 
     ajax: true, 
     url: 'The_Url_To_Load_Your_Data' 
    }).on("loaded.rs.jquery.bootgrid", function (s) { 
     //Now, display the cantidad_totales in your div or whatever 
     $('div#YourTotalDiv').html(cantidadTotales); 
    }); 
}) 
+0

はrespondeHandlerとのRequestHandler知りませんでした、ありがとうございました。この関数は問題を解決し、データを見てテーブルの外で使用することができます。 –

関連する問題