如何通过单击一个按钮将文本框值和 dxDatagrid 所有选定值插入数据库?

How to insert textbox value & dxDatagrid all selected value in database on one single button click?

我有输入标签(文本框)和 dxDatagrid。我能够将所有选定的值从 dxDatagrid 传递到数据库,但我也想通过单击一个按钮将文本框(在网格之外)值与其一起传递。

$("#myButton").dxButton({
    text: "Test",
    onClick: function () {
        var stones = (JSON.stringify(dataGrid.getSelectedRowsData()));
        console.log(stones);
        updatedetgridReturnShip(stones);
    }
});



function updatedetgridReturnShip(stonedetailsarr){
    $('#sloader').show();
    $.ajax({
        url: 'php/insertGridReturnShipment.php',
        dataType: 'json',
        type: "POST",
        data: {
            returnstonedetails: stonedetailsarr,
            txtRefnoval : txtRefnoval
        },
        success: function (result) {
            alert(result);
            $('#sloader').hide();
            $("#myImportModal").modal("hide");
        }
    });
}

PHP 服务器端代码:

$StoneArr = json_decode($returnstonedetails, true);

$updstmt = '';

foreach ($StoneArr as $Stone){
  $textboxval = $_POST['textboxval'];

  $refVal = json_decode($textboxval, true);

  $updstmt .= 'CALL return_ship_stones('.'"'.$Stone["carat"].'"'.',
  '.'"'.$Stone["clarity"].'"'.','.'"'.$Stone["color"].'"'.','.'"'.$Stone["invcno"].'"'.','.'"'.$Stone["invoicedate"].'"'.', '.'"'.$Stone["lab"].'"'.', 
  '.'"'.$Stone["measurement"].'"'.' , '.'"'.$Stone["ppt"].'"'.' , '.'"'.$Stone["qstonesid"].'"'.' , '.'"'.$Stone["qty"].'"'.' ,
  '.'"'.$Stone["reportno"].'"'.' , '.'"'.$Stone["shape"].'"'.' , '.'"'.$Stone["totalvalue"].'"'.', '.'"'.$refVal["referenceid"].'"'.');';
}

一次单击如何传递数据库中的文本框和 dxDatagrid 值

可以使用jquery方法从id输入的文本中获取值,传给ajax数据参数:

$('#refno').val().trim()

代码如下:

function updatedetgridReturnShip(stonedetailsarr){
    $('#sloader').show();

      $.ajax({
          url: 'php/insertGridReturnShipment.php',
          dataType: 'json',
          type: "POST",
          data: {
              returnstonedetails: stonedetailsarr,
              txtRefnoval : txtRefnoval,
              textboxval: $('#refno').val().trim()
          },
          success: function (result) {
              alert(result);
              $('#sloader').hide();
              $("#myImportModal").modal("hide");
          }
      });
  }

PHP代码:

<?
$returnstonedetails = $_REQUEST['returnstonedetails'];

$StoneArr = json_decode($returnstonedetails, true);

$updstmt = '';

foreach ($StoneArr as $Stone){
  $textboxval = $_REQUEST['textboxval'];
  $refVal = $textboxval;

  $updstmt .= 'CALL return_ship_stones('.'"'.$Stone["carat"].'"'.',
  '.'"'.$Stone["clarity"].'"'.','.'"'.$Stone["color"].'"'.','.'"'.$Stone["invcno"].'"'.','.'"'.$Stone["invoicedate"].'"'.', '.'"'.$Stone["lab"].'"'.', 
  '.'"'.$Stone["measurement"].'"'.' , '.'"'.$Stone["ppt"].'"'.' , '.'"'.$Stone["qstonesid"].'"'.' , '.'"'.$Stone["qty"].'"'.' ,
  '.'"'.$Stone["reportno"].'"'.' , '.'"'.$Stone["shape"].'"'.' , '.'"'.$Stone["totalvalue"].'"'.', '.'"'.$refVal.'"'.');';
}