var data= new DataManager({
url: 'http://localhost:56237/Home/UrlDatasource',
adaptor: new UrlAdaptor ,
crossDomain: true
}); // Making the request to server
listObj.dataSource = data; // Set the dataSource to component
listObj.dataBind(); // Call the dataBind to reflect the changes |
document.getElementById('btn').addEventListener('click',function(){
listObj.addItem({ShipCountry: 'America',CustomerID:'AMR'});
}) |
let value: string[] = ['ALFKI','ANATR','BOLID','BLONP']
// initialize MultiSelect component
let listObj: MultiSelect = new MultiSelect({
// bind the DataManager instance to dataSource property
dataSource: new DataManager({
url: 'http://localhost:56237/Home/UrlDatasource',
adaptor: new UrlAdaptor ,
crossDomain: true
}),
query: new Query().select(['ShipCountry', 'CustomerID']).take(10).addParams('additionalParams', JSON.stringify(value)),
// map the appropriate columns to fields property
fields: { text: 'ShipCountry', value: 'CustomerID' },
// set the placeholder to MultiSelect input element
placeholder: 'Select name',
// sort the resulted items
sortOrder: 'Ascending',
value: ['ALFKI','ANATR','BOLID','BLONP']
});
listObj.appendTo('#remote'); |
public JsonResult UrlDatasource([FromBody]Data dm, string additionalParams)
{
var val = OrdersDetails.GetAllRecords();
var Data = val.ToList();
var count = val.Count();
string[] splitResult = new string[] { };
if (dm.where != null)
{
Data = (from cust in Data
select cust).ToList();
}
if (additionalParams != null)
{
string[] seperators = { "[", "]", "," };
string replace = additionalParams.Replace("\"", "");
splitResult = replace.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
}
if (dm.take != 0)
Data = Data.Take(dm.take).ToList();
List<OrdersDetails> filterItem = new List<OrdersDetails>();
if (splitResult.Length != 0)
{
for (var i = 0; i<splitResult.Length; i++)
{
var filter = Data.Where(j => j.CustomerID.Equals(splitResult[i])).ToList();
filterItem.Add(filter[0]);
}
}
else
{
filterItem = null;
}
return Json(filterItem);
}
|