网格的数据源对Kendo UI中的下拉单元格的更改没有反应

时间:2018-08-28 20:31:18

标签: kendo-ui telerik

我正在Grid单元内使用DropdownList。在Grid中更改后,不会调用其DataSource.parameterMap和transport(console.log不会打印日志)。

  allUsersDataSource.fetch(function() {
    allUsers = allUsersDataSource.data();
  })

  var assignedUsersDataSource = new kendo.data.DataSource({
    transport: {
      read:{
        url: API+"nk/getassignedusers/"+documentId,
        dataType: "json"
      },
      create: {
        type: "POST",
        url: API+"nk/addusertodocument",
        dataType: "json"
      },
      update: {
        type: "POST",
        url: API+"nk/editusertodocument",
        dataType: "json"
      },
      destroy:{
        type: "POST",
        url: API+"nk/removeuserdocument",
        dataType: "json"
      },
      parameterMap: function(data, operation) {
        console.log ("parameterMap");
        if (operation === "destroy" ) {
          console.log("!!!!!!!!!!!!!!!destroy", data.models)
        }

        if (operation === "create" && data.UserID) {
          console.log("!!!!!!kendo.stringify(data.models)", kendo.stringify(data.models))
          console.log ("parameterMap: data.models: ",data.models);
          console.log("parameterMap: data.UserID: ", data.UserID)
          console.log("parameterMap: documentId: ", documentId)
          return {
            models: kendo.stringify(data.models),
            user_id: data.UserID,
            document_id: documentId,
            user: user
          };
        }
      }
    },
    change: function(e) {
      console.log("!!!!!!change: e.action:: " + e.action);
      console.log("!!!!!!change: e.action:: ", e);
      console.log("!!!!!!change: e.action:: ", e.models);
      console.log("!!!!!!change: e.action:: ", e.UserID);
    },
    pageSize: 4,
    schema: {
      model: {
        fields: {
          UserName: { editable: false, nullable: true },
          Surname: { editable: false, nullable: true },
          UserID: { field: "UserID", defaultValue: 1 },
          GroupName: { editable: false, nullable: true },
        }
      }
    }
  });

  var _grid = $("\#grid-single-user-groups").kendoGrid({
    dataSource: assignedUsersDataSource,
    filterable: true,
    scrollable: false,
    // toolbar: ["create", "save"],
    toolbar: ["create"],
    pageable: true,
    columns: [
      {
        field: "UserID", width: "100%",
        editor: userDropDownEditor,
        title: "Agent",
        template: function(userID) {
          for (var idx = 0, length = allUsers.length; idx < length; idx++) {
            if (allUsers[idx].UserNameID == userID.UserID) {
              return allUsers[idx].Login;
            }
          }
        }
      },
      { command: [ "destroy"], title: "&nbsp;", width: "250px" }
    ],
    editable: {mode: "incell"},
    save: function(e) {

      if (e.values.UserID !== "") {
        if (e.values.UserID !== e.model.UserID) {
          console.log("!!!UserID is modified");
        }
      } else {
        e.preventDefault();
        console.log("UserID cannot be empty");
      }

      if (e.values.UserName !== "") {
        if (e.values.UserName !== e.model.UserName) {
          console.log("!!!UserName is modified");
        }
      } else {
        e.preventDefault();
        console.log("UserName cannot be empty");

      }


    },
    saveChanges: function(e) {
      if (!confirm("Are you sure you want to save all changes?")) {
        e.preventDefault();
      }else{
        console.log("!!!!confirmeddddddd", documentId)

        $.ajax({
          url: API+"nk/removeuserdocument",
          type: 'POST',
          dataType: "json",
          data: 
            user: user,
            documentId: documentId
          },
          success : function(response) {
            console.log("Pomyslnie usunięto wszystkich użytkowników.", response)
          },
          error: function(xhr, status, error) {
            alert(xhr.responseText);
            var err = eval("(" + xhr.responseText + ")");
            console.log("NIE usunięto użytkowników.", err.Message)
          }
        });
      }
    },
    remove: function(e) {
      console.log("!!!!!Removing", e.model.UserID);
    },

    cellClose: function(e){
      console.log('Closing Cell Edit e::', e);
      console.log('Closing Cell Edit e.type::', e.type);
      console.log('Closing Cell Edit e.container::', e.container);
      console.log('Closing Cell Edit e.model::', e.model);
      console.log('!!!! Closing Cell Edit e.model.UserID::', e.model.UserID);
      console.log('Closing Cell Edit e.model.isNew()::', e.model.isNew());
      console.log('Closing Cell Edit e.sender ::', e.sender );
      e.container.find("input[name=id]")
    }
  });

  function userDropDownEditor(container, options) {
    $('<input data-bind="value:' + options.field + '"/>')
    .appendTo(container)
    .kendoDropDownList({
      dataTextField: "Login",
      dataValueField: "UserNameID",
      filter: "contains",
      dataSource: allUsersDataSource,
      valuePrimitive:true,
      select: function(e) {
        if (e.item) {
          var dataItem = this.dataItem(e.item);
          console.log("event :: select (" + dataItem.Login + " : " + dataItem.UserNameID + ")");
        } else {
          console.log("nie jest dobrze");
        }
      }
    })
  }

我想实时发送数据,而不是使用“保存更改”按钮到整个网格。

(我的帖子主要是代码,我需要再写一些非代码的单词)

0 个答案:

没有答案