2016-11-21 5 views
0

phpgrid(phpgrid.org)の行を削除した後、Sub Total div/text boxの値を更新する必要があります。削除する前にphpgridの行を削除した後にテキストボックスの値を変更します

enter image description here

二行を削除した後:

enter image description here

<div id="sub_total_div"> 
<input name="txtSubTotal" type="text" id="txtSubTotal" size="15" value="<?php 
$sql=mysqli_query($connection,'select sum(amount) from sales_temp'); 
$row = mysqli_fetch_array($sql); 
echo $row[0]; 
?>"/> 
</div> 

は私を助けてください。

編集コード:

function submitdata() { 
       var listItemName = document.getElementById("listItemName").value; 
       var listStock = document.getElementById("listStock").value; 
       var txtUnitPrice = document.getElementById("txtUnitPrice").value; 
       var txtQuantity = document.getElementById("txtQuantity").value; 
       var listCustomer = document.getElementById("listCustomer").value; 
       var txtReceiptNo = document.getElementById("txtReceiptNo").value; 
       var TheDate = document.getElementById("TheDate").value; 

       // Returns successful data submission message when the entered information is stored in database. 
       var dataString = {listItemName:listItemName, listStock: listStock, txtUnitPrice: txtUnitPrice, txtQuantity: txtQuantity, listCustomer: listCustomer, txtReceiptNo: txtReceiptNo}; 
       if (listItemName == '' || listStock == ''|| txtUnitPrice == ''|| txtQuantity == ''|| listCustomer == ''|| txtReceiptNo == ''|| TheDate == '') { 
       salesitemsAddFail(); 
       } 
       else { 
         // AJAX code to submit form. 
         $.ajax({ 
         type: "POST", 
         url: "/pms/includes/functions/sales_temp_functions.php", 
         data: dataString, 
         cache: false, 
         success: function(html) {  

       //reload the sales datagrid once add the item details to temporary table (sales_temp) 
       $('#list').trigger("reloadGrid",[{page:1}]); 
       //window.location.reload(); 
       //refresh/update the sub total value when adding 
       $("#sub_total_div").load(location.href + " #sub_total_div"); 
         } 
         }); 
        } 
     } 
+0

あなたのjavascriptを表示 – prasanth

+0

@prasad上記のjavascriptコードを追加しました。 – EKBG

+0

なぜphpで値を追加するside.better use with javascript side – prasanth

答えて

2

新しいPHPファイルを作成します。 Gettotal.php

$sql=mysqli_query($connection,'select sum(amount) from sales_temp'); 
$row = mysqli_fetch_array($sql); 
echo $row[0]; 

をあなたのJSコードは次のようになります。

 submitdata() { 
         var listItemName = document.getElementById("listItemName").value; 
         var listStock = document.getElementById("listStock").value; 
         var txtUnitPrice = document.getElementById("txtUnitPrice").value; 
         var txtQuantity = document.getElementById("txtQuantity").value; 
         var listCustomer = document.getElementById("listCustomer").value; 
         var txtReceiptNo = document.getElementById("txtReceiptNo").value; 
         var TheDate = document.getElementById("TheDate").value; 

         // Returns successful data submission message when the entered information is stored in database. 
         var dataString = {listItemName:listItemName, listStock: listStock, txtUnitPrice: txtUnitPrice, txtQuantity: txtQuantity, listCustomer: listCustomer, txtReceiptNo: txtReceiptNo}; 
         if (listItemName == '' || listStock == ''|| txtUnitPrice == ''|| txtQuantity == ''|| listCustomer == ''|| txtReceiptNo == ''|| TheDate == '') { 
         salesitemsAddFail(); 
         } 
         else { 
           // AJAX code to submit form. 
           $.ajax({ 
           type: "POST", 
           url: "/pms/includes/functions/sales_temp_functions.php", 
           data: dataString, 
           cache: false, 
           success: function(html) { 
           //reload the sales datagrid once add the item details to temporary table (sales_temp) 
           $('#list').trigger("reloadGrid",[{page:1}]); 
           //Ajax call to get the sub 
           $("#sub_total_div").load("gettotal.php"); 

          } 
          }); 
         } 
       } 

注:これは、一緒に行くために適切な方法ではありませんが、あなたの場合には、これは

+0

これは働く友人ではありません。 – EKBG

+0

新しいファイルのajax呼び出しに適切なパスを指定しましたか? – Akshay

+0

はい私は正確なパスを与えました。 – EKBG

0

に動作します私は、解決策を見つけた(これも削除した後に)各リフレッシュの後にトリガされloadCompleteイベントの合計を計算するdo_onload(id)を追加

function do_onload(id) 
{ 
    //alert('Simulating, data on load event') 

    var s = $("#list").jqGrid('getCol', 'amount', false, 'sum'); 
    jQuery("#txtSubTotal").val(s); 
} 

phpgridコードを適宜変更しました。

$opt["loadComplete"] = "function(ids) { do_onload(ids); }"; 
$grid->set_options($opt); 
-1

Iは、解決策を見つけた(また、削除した後)、各リフレッシュの後にトリガされるloadCompleteイベントに合計を計算するdo_onload(id)を添加

function do_onload(id) 
{ 
//alert('Simulating, data on load event') 

var s = $("#list").jqGrid('getCol', 'amount', false, 'sum'); 
jQuery("#txtSubTotal").val(s); 
} 

、従ってphpgridコードを変更。

$opt["loadComplete"] = "function(ids) { do_onload(ids); }"; 
$grid->set_options($opt); 
関連する問題