简体   繁体   中英

Change text box value after deleting phpgrid row

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

Before Delete:

在此处输入图片说明

After deleting the second row:

在此处输入图片说明

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM