Created
May 10, 2018 00:17
-
-
Save fluxdigital/2f307d3bac3ab3d05a9d271d4d9f77b0 to your computer and use it in GitHub Desktop.
An example Sitecore Multilist with an external datasource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FluxDigital.Sitecore.Extensions.Fields | |
{ | |
public class CryptoMultilist : BaseExternalMultiList | |
{ | |
private List<CryptoCoin> _coinList; | |
protected override void InitRendering() | |
{ | |
CryptoService cryptoService = new CryptoService(); | |
_coinList = cryptoService.CointList(); | |
} | |
protected override IEnumerable<KeyValuePair<string, string>> GetNonSelectedItems() | |
{ | |
var nonSelectedGroups = new List<KeyValuePair<string, string>>(); | |
_coinList.ForEach(coin => nonSelectedGroups.Add(new KeyValuePair<string, string>(coin.Id, coin.CoinName))); | |
return nonSelectedGroups; | |
} | |
protected override IEnumerable<KeyValuePair<string, string>> GetSelectedItems() | |
{ | |
var selectedCoinIds = Value.Split('|'); | |
var selectedCoins = new List<KeyValuePair<string, string>>(); | |
foreach (var selectedGroupId in selectedCoinIds) | |
{ | |
var coin = _coinList.FirstOrDefault(g => g.Id == selectedGroupId); | |
if (coin != null) selectedCoins.Add(new KeyValuePair<string, string>(coin.Id, coin.CoinName)); | |
} | |
return selectedCoins; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment