【问题标题】:Insert data from HTML form into Kendo grid data将 HTML 表单中的数据插入到 Kendo 网格数据中
【发布时间】:2019-08-19 01:55:38
【问题描述】:

我尝试在下拉列表中选择数据,然后提交到剑道网格。但是,数据未能插入到网格中。有人有想法或解决方案吗?

HTML 提交按钮

<button class="k-button" id="btnSave" value="submit" style="float:right; padding: 5px 20px; border-radius: 4px;" >Submit</button>

JavaScript 按钮提交

    //AJAX call for button
    $("#btnSave").kendoButton();
    var button = $("#btnSave").data("kendoButton");
    button.bind("click", function(e) {

    var test = $("#accountLedger").val()

    $.ajax({
        url: "../GroupManagement/get.php",
        type: "POST",
            data: {
                method: "addGroup",
                accountLedgerID: $("#accountLedgerID").val()

                },
                success: function () {                
                kendo.alert ('success');

JavaScript 下拉菜单

        $("#accountLedger").kendoDropDownList({
        dataTextField: "accountLedgerName",
        dataValueField: "accountLedgerID",
        optionLabel: "Choose account ledger",
        dataSource: {
            transport: {
                read: {
                    url:  "./getCoaGroup.php",
                    type: "POST",
                    data: function() {
                            return { 
                                method: "getAccLedger",
                        }
                    }
                },
            },
        },
        //change: onChange(),
        change: function(e){
            console.log(this.value());
            $('#grid').data('kendoGrid').dataSource.read();
            homogeneous.read();
        }
    }).data('kendoDropDownList');

    dropdownlist = $("#accountLedger").data("kendoDropDownList");

JavaScript 剑道网格

columns: [
            columns: [
                { field: "active", title:" ", filterable:false,
                template: "# if( data.active == 'y' ){# <span class='k-icon ehors-status-active-icon'></span> #} else {# <span class='k-icon ehors-status-inactive-icon'></span> #} #" },
                { field: "accountLedgerID", title:"Ledger Name", editor: getLedger, 
                template:" #= (data.accountLedgerID) ? kendo.toString (data.accountLedgerName): '' #" }]

PHP 插入

   /* ADD */
 function addGroup() {
global $ehorsObj;
$accountID  = (isset($_POST['accountID']) ? $_POST['accountID'] : '');
$accountLedgerID   = (isset($_POST['accountLedgerID']) ? $_POST['accountLedgerID'] : '');

/ check unique /
$sqlCount   =   "SELECT COUNT AS TOTAL FROM tblAccAccounts
                 WHERE accountID != '" . $accountID . "'
                 AND accountLedgerID = '" . $accountLedgerID . "'
                 ";
$GetResult = $ehorsObj->FetchData($sqlCount, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
while ($row = $GetResult->fetch()){
    $total = $row ['TOTAL'];
}
if ($total == 0){

    $accountID = $ehorsObj->EHORS_PK(tblAccAccounts);
    $sqlAdd     =   "INSERT INTO tblAccAccounts
                    SET accountID = '" . $accountID . "',
                    accountLedgerID = '" . $accountLedgerID . "',                       
                    dateTimeEmployee = NOW() ";     

    $ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);        

    $accountLog = $ehorsObj->EHORS_PK(tblAccAccountsLog);
    $sqlAddLog  =   "INSERT INTO tblAccAccountsLog
                    SET accountLog = '" . $accountLog . "',
                    accountID = '" . $accountID . "',
                    accountLedgerID = '" . $accountLedgerID . "',
                    dateTimeEmployee = NOW(),
                    active = 'y' ";
$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);  
}else{
    echo "Record already exist";
}}

这是我的输出

如果你看到图片,列账名称上方的网格没有数据。它假设用户选择下拉菜单然后单击提交。之后,下拉列表中的选定数据将插入到网格中。希望任何人都可以对此提供任何参考。谢谢!

【问题讨论】:

    标签: javascript php html kendo-grid


    【解决方案1】:

    在“传输”和“读取”之后的代码中应该有: {

    以下部分代码已修复:

    dataSource: {
            transport: {
                read: {
                    url:  "./getCoaGroup.php",
                    type: "POST",
                    data: function() {
                            return { 
                                method: "getAccLedger",
                        }
                    }
                },
            },
    

    【讨论】:

    • 我已经放了,但是什么也没发生
    【解决方案2】:

    我不确定它是否有效,但您是否尝试将 accountLedgerID 更改为其他名称。我也遇到了同样的问题,可能是变量名混淆了。

    JavaScript 按钮提交

    accLedgerID: $("#accountLedgerID").val()
    

    PHP

    $accLedgerID= (isset($_POST['accLedgerID']) ? $_POST['accLedgerID'] : '');
    

    【讨论】:

      猜你喜欢
      • 2012-01-04
      • 2014-04-27
      • 1970-01-01
      • 2019-01-12
      • 2019-06-06
      • 2017-08-08
      • 1970-01-01
      • 2022-01-24
      相关资源
      最近更新 更多