javascript - jqGrid 与 MySQL 中的相关表

标签 javascript php mysql jqgrid

早上好,

很长一段时间后我要回到 php 和 javasvript,并且我使用 jqGrid 插件来创建网格。我用的很好,编辑高,修改没有问题。当我想使用有相关数据的表时我可以找到问题。

该表是部分加盟商的费用,与加盟商本身相关。要编辑,请使用 jqgrid 表单。我尝试进行选择,因此他们选择了附属机构,但我不加载数据。 我已经给它跑了很多圈,但我不知道我会发生什么。说我有点生锈了。抱歉,如果有非常严重的失败。

我把我的代码。

索引.html:

<script type="text/javascript">
     $(document).ready(function(){
           jQuery("#tblCuotas").jqGrid({
           url:'cargaCuotas.php',
              editurl: "editCuotas.php",
           datatype: 'json',
           mtype: 'POST',
           colModel:[
              {
                 label: 'ID Cuota',
                 name: 'idCuota',
                 index:'idCuota',
                 width: 50,
                 key: true,
                 editable: true,
                 hidden: true
              },
              {
                 label: 'Num. Cuota',
                 name: 'NumD',
                 index:'NumD',
                 width: 50,
                 editable: true,
                 editoptions : { required: true, placeholder: "Número de Cuota requieredo"}
              },
              {
                 label: 'Num. Afiliado',
                 name: 'NumAfiliado',
                 index:'NumAfiliado',
                 width: 150,
                 editable: true,
                 edittype: 'select',
                 formatter:'select',
                 editoptions : { dataurl: 'afiliadosSelect.php' },
                 editrules : { required: true, placeholder: "Número de Cuota Afiliado"}
              },
              {
                 label: 'Nombre',
                 name: 'NOMBRE',
                 index:'NOMBRE',
                 width: 300,
                 editable: true
              },
              {
                 label: 'Cuota',
                 name: 'CUOTA',
                 index:'CUOTA',
                 width: 150,
                 editable: true,
                 editoptions : { required: true, placeholder: "Importe de la cuota requieredo"}
              },
              {
                 label: 'Mes',
                 name: 'MES',
                 index:'MES',
                 width: 120,
                 editable: true,
                 editoptions : { }
              },
              {
                 label: 'Año',
                 name: 'ANNO',
                 index:'ANNO',
                 width: 50,
                 editable: true,
                 editoptions : { }
              },
              {
                 label: 'Pago',
                 name: 'PAGO',
                 index:'PAGO',
                 width: 50,
                 editable: true,
                 edittype: 'select',
                 editoptions : { value: "Y:SI;N:NO" }
              },
              {
                 label: 'Forma Pago',
                 name: 'FormaPago',
                 index:'FormaPago',
                 width: 100,
                 editable: true,
                 editoptions : { }
              }

           ],   
              loadonce: false,
              width: window.innerWidth-20,
              height: window.innerHeight-150,
           pager: '#paginacion',
           rowNum: 50,
           rowList:[50,100,150],
           sortname: 'NumD',
           sortorder: 'asc',
           viewrecords: true,
           caption: 'CUOTAS'
        });   


        jQuery("#tblCuotas").jqGrid('navGrid','#paginacion',
           {edit:true,add:true,del:true},
           // options for the Edit Dialog

           {
              html5Check :  true,
              editCaption: "The Edit Dialog",
              recreateForm: true,
              checkOnUpdate : true,
              checkOnSubmit : true,
              closeAfterEdit: true,
              reloadAfterEdit:true,
              reloadAfterSubmit:true,
              errorTextFormat: function (data) {
                       return 'Error: ' + data.responseText
                   },
              buttons : [
                 {
                    side : "right",
                    text : "Afiliado",
                    position : "first",
                    click : function( form, params, event) {
                       alert("Custom action in search form");
                    }
                 }
                 ]
                  },


           // options for the Add Dialog
           {
              closeAfterAdd: true,
              html5Check : true,
              recreateForm: true,
              errorTextFormat: function (data) {
                 return 'Error: ' + data.responseText
              }
           },
           // options for the Delete Dailog
           {
              errorTextFormat: function (data) {
                 return 'Error: ' + data.responseText
              }
           });

     });


  </script>

afiliadosSelect.php:

 <?php
    include "../class/tAfiliados.php";

   echo '<script>alert("Custom action in search form");</script>';
   $oAfiliado = new tAfiliados(1, 0, 1, 1);
   $respuesta = $oAfiliado->selectAfiliados();


    echo $respuesta;
?>

tAfiliados.php:

    <?php

    include 'tMySQL.php';



class tAfiliados
{

   public function selectAfiliados()
   {
      $oMySQL = new tMySQL();

      if ($oMySQL->bConnect)
      {
         $cSQL ="SELECT COUNT(*) AS cuantos FROM afiliados WHERE borrado=0";   
         $this->fila = $oMySQL->countQuery($cSQL);
         $this->cuantos = $this->fila['cuantos'];

         $query = "SELECT idAfiliado, NumAfiliado, NOMBRE FROM afiliados WHERE borrado=0 ORDER BY NOMBRE"; 
         $result = $oMySQL->GetQuery($query);

         $response ='<select>';
         $i=0;
         while( $i <= $this->cuantos ) {
            $response .= '<option value="'.$result[$i]['NumAfiliado'].'">'.$result[$i]['NOMBRE'].'</option>';
            $i++;
         }
         $response .= '</select>';

      }

      $oMySQL->Close();   
      return $response;
   }
}

?>

问候并非常感谢。

最佳答案

请从您的代码中删除此行:

echo '<script>alert("Custom action in search form");</script>';

这会导致加载数据时出现问题。数据应该只包含 html 数据,仅此而已。

此回显导致数据无法加载到网格中。

更新:

抱歉,刚才我看了你的代码。 JavaScript 区分大小写。

请更换

editoptions : { dataurl: 'afiliadosSelect.php' },

editoptions : { dataUrl: 'afiliadosSelect.php' },

更新2

我已经根据您的设置准备了一个演示,效果很好。这里is the link 。请检查网格所在文件中相关玩具中的 afiliadosSelect.php 路径是否正确。在这种情况下,您应该在控制台中收到错误。

关于javascript - jqGrid 与 MySQL 中的相关表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54199357/

相关文章:

javascript - 是否有用于 javascript 的 flex - bison 解析器?

javascript - ColdFusion 从另一个文件调用 Bootstrap 模式

php - 将内容放入 iframe 中(在 ie 中中断)

javascript - 如何从firebase存储中获取所有下载网址?

mysql - 如何在现有行的另一列中添加具有默认值的MySQL表列

javascript - 如何使用javascript乘以时间?

javascript - 以编程方式在 Google Chrome 中固定标签页

php - 简单 'SELECT field FROM table_name where TO = "$to"' 返回 MySQL 错误 1064

php - NSDate 到 MySQL 日期

php - 使用 PDO 进行多次插入