如何在SharePoint中利用Jquery Chosen建立新的人員選取器

來源:互聯網
上載者:User

基於SharePoint平台開發時,人員選取器使用頻率是非常高的,但是原生的人員選取器使用太麻煩,而且非常笨拙,非常不友好,特別是對呆在政府部門的老爺們,要讓他們手動輸入人員,簡直就是癡心妄想。總之一句話,越簡單越好。

為了讓客戶滿意,必須要對人員選取器進行改造,原生的PeopleEditor徹底拋棄。只能另闢蹊徑,尋找適合的JQuery外掛程式,建立新的人員選取器,分析了一下需求,可以歸納新的人員選取器必須支援如下情況:

技術服務人員的多選,比如像會議、通知需要對多人進行發送,當然也要支援刪除。

對於單選的人員選取器,可以刪除選中的人員。

不管單選還是多選,支援Jquey AutoComplete那樣索引功能。

找來找去,發現Jquery Chosen功能十分強大,完全滿足我的需求,更多的功能參照Chosen官網:

http://harvesthq.github.io/chosen/

利用Jquery Chosen進行改造

多選的人員選取器

支援多選,點擊X即可取消選中,當然還支援索引,如下所示:

配置也是十分簡單,首先你的有一個Select,譬如:

 <asp:DropDownList runat="server" ClientIDMode="Static" ID="ddlPeopleChosen" data-placeholder="選擇與會者..."class="chzn-select" multiple style="width:397px;" ></asp:DropDownList>

注意下:data-placeholder意為著未選人員時的預設文本,multiple意味著支援多選。

接下來,需要對其添加資料來源,注意,對於單人員選取器,Chosen作者說如果要顯示預設的文本提示,需要加入一個空的Option到Select中(第一個)。

注意:我的人員不是從AD中取出,而是我們有一個存放人員的List(人事檔案),為了確保該List的人員都可以登陸OA,特意和Web.AllUser中進行比較,當然也可以不必要,這樣做保險點。

public static void GetFromCache(SPWeb _currentWeb)        {            #region 從緩衝中讀            if (System.Web.HttpContext.Current.Cache["peopleList"] == null)            {                //People 集合:將SharePoint中的User作為資料來源集合加入DropDownList中                List<People> peopleList = new List<People>();                //Note: on single selects, the first element is assumed to be selected by the browser.                 //To take advantage of the default text support,                 //you will need to include a blank option as the first element of your select list.                peopleList.Add(new People());                People p = null;                SPList employeeList = _currentWeb.Site.AllWebs["rsgl"].Lists["人事檔案"];                //擷取所有可訪問網站的使用者                SPUserCollection userCollection = _currentWeb.AllUsers;                //轉換為List集合                List<SPUser> listUsers = userCollection.Cast<SPUser>().ToList();                foreach (SPListItem item in employeeList.Items)                {                    string displayName = item["Title"].ToStringOrEmpty();                    //迴圈便利擷取SPUser                    foreach (SPUser user in listUsers)                    {                        if (displayName == user.Name)                        {                            string loginName = user.LoginName;                            p = new People { LoginName = loginName, DisplayName = displayName };                            peopleList.Add(p);                        }                    }                }                    System.Web.HttpContext.Current.Cache["peopleList"] = peopleList;            }            #endregion                   }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.