Telerik的kendoui网格没有得到分配了从其他数据参数(对电网的需求负荷)(telerik

2019-10-19 06:41发布

现我与装载电网的问题取决于传递到电网参数。 我正在开发一个搜索页面中,我有一个文本框和按钮。 我将显示按钮回吐文本框中输入文本作为参数的单击事件的网格。

我的文本框和按钮:

 <divid="SearchSection">
    <input  type="text"id="txtSearch"class="k-textbox"/> 
    <buttonid="btnSearch"  class="k-button"style="width:150px">Search</button>
</div>

我的网格:

        <divid="ADUserSection"> 
        List of users in Active directory:
               @(Html.Kendo().Grid<ADUser>()
                     .Name("kADUser")
                    .Columns(columns =>
                                  {
                                   columns.Bound(p => p.UserLoginName);
                                   columns.Bound(p => p.UserDisplayName);
                                  })
                     .AutoBind(false)
                     .DataSource(ds => {
                                         ds.Ajax()
                                         .Read(read =>
                                           {
                                            read.Action("GetADUser", "ManageUsers").Data("AdditionalData");
                                            });
                                         })

                            )
               </div>

我的JavaScript在我传递了额外的数据:

       function AdditionalData() {
         debugger;
         var text = $("#txtSearch").val().trim();

          return{ searchText: text };   
            *****The Problem happens here: The searchText never get assigned value intext ****
               }

我的剧本在我打电话的单击事件并捕捉文本框中输入:

   <script>
       $(document).ready(function () {
         $("#ADUserSection").fadeIn();
       $("#btnSearch").click(function () {
              debugger;
         var text =AdditionalData().toString();
          var grid = $("#kADUser").data("kendoGrid");
       grid.dataSource.read({searchText:text});
         });
          });
        </script>

我的控制器方法:

   publicJsonResult GetADUser([DataSourceRequest] DataSourceRequest request, string searchText) {
        viewmodel.searchedADUser = model.GetUserFromAD(searchText);
          return Json(viewmodel.searchedADUser.ToList().ToDataSourceResult (request), JsonRequestBehavior.AllowGet);
        } 

模型:

         public class ADUser
          {
          public string UserLoginName { get; set; }
                public string UserDisplayName { get; set; }
            }
           public List<ADUser> GetUserFromAD(string name) //Get Network Users (AD)
                {
                  var searchUser = newList<ADUser>();
                 var domainContext = newPrincipalContext(ContextType.Domain);
                    var groupPrincipal = GroupPrincipal.FindByIdentity(domainContext,           IdentityType.SamAccountName, "Domain Users");
                  UserPrincipal user = newUserPrincipal(domainContext);
                 if (!String.IsNullOrEmpty(name))
                    {
                      user.Enabled = true;
                       user.Name = name + "*";
                          PrincipalSearcher pS = newPrincipalSearcher();
                           pS.QueryFilter = user;
                            PrincipalSearchResult<Principal> results = pS.FindAll();

                            foreach (var item in results)
                             {
                                  var users = new FMSystemWeb.Models.ADUser();
                                   users.UserLoginName = item.SamAccountName;
                                   users.UserDisplayName = item.DisplayName;
                                   searchUser.Add(users);
                              }
                         }
                       return searchUser;
                       }

我的视图模型:

             public class ViewModelManageUsers
              {
                public List<UserRoleList> assignedUserRole { get; set; }
                public List<ADUser> searchedADUser { get; set; }
                public List<AvailableRoles> availableRoles { get; set; }
              }

请帮我寻找到的问题。 我走过这也解释了这样的场景,并曾试图实现各种职位,但没有运气了。

JavaScript函数

 function AdditionalData() {
      never gets the data assigned to my parameter 
    searchText

因此,我的控制器的方法总是得到的参数空和电网不显示任何结果。

Answer 1:

按需事件

  // Bouquet combo change event
    $('#BooketID').live('change', function () {
        FillChannelGridByBouquetID();
    });

用于电网负荷组参数

/* Load kendo grid by bouquetID*/
    function FillChannelGridByBouquetID() {
        var a = {};
        a.BooketID = $("#BooketID option:selected").val();
        var mAGrid = $('#CustomerPackageChannelKendoGrid').data('kendoGrid');
        mAGrid.dataSource.read(a);
        }

$("#CustomerPackageChannelKendoGrid").kendoGrid({
        dataSource:
        {
            transport:
            {
                read: "ChannelReadByBooketID",
            },
            schema:
            {
                model:
                {
                    fields:
                    {
                        SelectColumn: {type: "boolean"},
                        ChannelID: { type: "string" },
                        BooketName: { type: "string" },
                        ChannelName: { type: "string" },
                    }
                }
            },
            pageSize: 20,
            serverPaging: false,
            serverFiltering: false,
            serverSorting: false
        },
        height: 200,
        filterable: true,
        groupable: true,
        sortable: true,
        resizable: true,                                                                
        pageable:
        {
            refresh: false,
            pageSizes: [20, 40, 60, 80, 100]
        },
        columns:
        [
            {
                field: "SelectColumn", title: " ", width: "5%",
                template: "<input type='checkbox' #= SelectColumn ? checked='checked':'' # class='chkbx' />"
            },

            { field: "ChannelID", title: "ChannelID", hidden: true, filterable: false, sortable: false },
            { field: "BooketName", title: "Bouquet Name", width: "30%" },
            { field: "ChannelName", title: "Channel Name", width: "30%" },
        ]
    });

调节器

public JsonResult ChannelReadByBooketID(CustomerPackageViewModel booketModel)
        {
            var models = GetAllChannelByBooketID(booketModel.BooketID.ToString());
            return Json(models, JsonRequestBehavior.AllowGet);
        }      

 private List<ChannelViewModel> GetAllChannelByBooketID(string pBooketID)
        {
            Guid gBooketID;

            if (!Guid.TryParse(pBooketID, out gBooketID))
            {
                return null;
            }

            var ViewModels = _bCService.BillingUnit.ChannelRepository.Get(t => t.BooketID == gBooketID).ToList().Select(
                 md => new ChannelViewModel
                 {
                     ChannelID = md.ChannelID,
                     ChannelName = md.ChannelName,
                     BooketID = md.BooketID,
                     BooketName = md.DJBL_tblBooket.BooketName

                 }).OrderBy(o => o.BooketName);

            return ViewModels.ToList();
        }


文章来源: telerik kendoui grid not getting assigned with the parameter from additional data(on demand load of grid)