首页 文章

select2大量记录

提问于
浏览 1668
1

我正在使用select2下拉列表 . 它适用于较少数量的物品 . 但是当列表很大(超过40000项)时,它确实会变慢 . 它在IE中速度最慢 .

否则简单的Dropdownlist工作非常快,直到1000条记录 . 这种情况有没有解决方法?

1 回答

  • 1
    ///////////////**** Jquery Code *******///////////////
    var CompanypageSize = 10;
    
    function initCompanies() {
            var defaultTxtOnInit = 'a';
            $("#DefaultCompanyId").select2({
                allowClear: true,
                ajax: {
                    url: "/SignUpTemplate/GetCompanies",
                    dataType: 'json',
                    delay: 250,
                    global: false,
                    data: function (params) {
                        params.page = params.page || 1;
                        return {
                            keyword: params.term ? params.term : defaultTxtOnInit,
                            pageSize: CompanypageSize,
                            page: params.page
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.result,
                            pagination: {
                                more: (params.page * CompanypageSize) < data.Counts
                            }
                        };
                    },
                    cache: true
                },
                placeholder: {
                    id: '0', // the value of the option
                    text: '--Select Company--'
                },
                width: '100%',
                //minimumInputLength: 3,
            });
        }
    
    
    //////////******* Have to initialise in .ready *******///////////////
    
     $(document).ready(function () {
    
            initCompanies();
        });
    
    //////////******* C# code :: Controller is : SignUpTemplateController************/////
    
    public JsonResult GetCompanies(string keyword, int? pageSize, int? page)
        {
            int totalCount = 0;
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                List<Companies> listCompanies = Companies.GetAll(this.CurrentTenant, (keyword ?? string.Empty).Trim(), false, 11, page.Value, pageSize.Value, ref totalCount, null, null, null, null, null).ToList();
                var list = listCompanies.Select(x => new { text = x.CompanyName, id = x.CompanyId }).ToList();
    
                return Json(new { result = list, Counts = totalCount }, JsonRequestBehavior.AllowGet);
            }
    
            return Json(null, JsonRequestBehavior.AllowGet);
        }
    

相关问题