删除phpgrid行后更改文本框值

时间:2016-11-21 08:17:04

标签: javascript php jquery html phpgrid

我需要在删除phpgrid(phpgrid.org)行后刷新Sub Total div / text box值。

删除前:

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

3 个答案:

答案 0 :(得分: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");

                             }
                           });
                         }
                 }

注意:这不是适当的方法,但在你的情况下,这将有效

答案 1 :(得分:0)

我找到了解决方案,添加do_onload(id)来计算每次刷新后触发的loadComplete事件总数(也在删除后)

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

答案 2 :(得分:-1)

我找到了解决方案,添加do_onload(id)来计算每次刷新后触发的loadComplete事件总数(也在删除后)

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