0

I need to refresh the Sub Total div/text box value after deleting the row of phpgrid (phpgrid.org).

Before Delete:

enter image description here

After deleting the second row:

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>

Please help me.

Edited code:

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");
                         }
                         });
                     }
         }
4

3 回答 3

2

Create a new php file: Gettotal.php

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

your js code will be:

        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");

                             }
                           });
                         }
                 }

Note : This is not proper method to go with but in your case this will work

于 2016-11-21T08:39:56.530 回答
0

I found the solution, added the do_onload(id) to calculate the total on loadComplete event which is triggered after each refresh (also after delete)

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

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

And changed the phpgrid code accordingly.

$opt["loadComplete"] = "function(ids) { do_onload(ids); }";
$grid->set_options($opt);
于 2016-11-30T05:10:56.127 回答
-1

I found the solution, added the do_onload(id) to calculate the total on loadComplete event which is triggered after each refresh (also after delete)

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

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

And changed the phpgrid code accordingly.

$opt["loadComplete"] = "function(ids) { do_onload(ids); }";
$grid->set_options($opt);
于 2016-11-30T05:35:51.407 回答