Example 1: Two drop down list binding. First one bind to int and the second one bind to an object.

    <div class="col-sm-2 p-xxs">
        <div class="filter-group">
            <label class="col-form-label">Year</label>
            <SfDropDownList @bind-Value="@SelectedYear" DataSource="@YearList" TItem="InvestmentAccountBalance" TValue="int">
                <DropDownListEvents ValueChange="FilterChanged" TItem="InvestmentAccountBalance" TValue="int"></DropDownListEvents>
                <DropDownListFieldSettings Value="BalanceYear" Text="BalanceYear"></DropDownListFieldSettings>
            </SfDropDownList>
        </div>
    </div>
    <div class="col-sm-2 p-xxs">
        <div class="filter-group">
            <label class="col-form-label">Account</label>
            <SfDropDownList @bind-Value="@SelectedAccount" DataSource="@AccountList" TItem="InvestmentAccount" TValue="InvestmentAccount">
                <DropDownListEvents ValueChange="FilterChanged" TItem="InvestmentAccount" TValue="InvestmentAccount"></DropDownListEvents>
                <DropDownListFieldSettings Value="InvestmentAccountId" Text="InvestmentAccountName"></DropDownListFieldSettings>
            </SfDropDownList>
        </div>
    </div>
        public List<InvestmentAccount> AccountList { get; set; }

        public List<InvestmentAccountBalance> YearList { get; set; }

        public int SelectedYear { get; set; }
        public InvestmentAccount SelectedAccount { get; set; }

        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            this.AccountList = new List<InvestmentAccount>();
            this.AccountList.Add(new InvestmentAccount { InvestmentAccountId = 0, InvestmentAccountName = "All" });
            this.AccountList.AddRange((await InvestmentService.GetAccountList(Convert.ToInt32(this.OrgId))).OrderBy(a => a.InvestmentAccountName).ToList());

            this.AccountBalanceList = (await InvestmentService.GetAccountBalanceList(Convert.ToInt32(this.OrgId)));

            this.YearList = new List<InvestmentAccountBalance>();

            foreach (var item in this.AccountBalanceList.Select(a => new { a.BalanceYear }).Distinct().OrderByDescending(a => a.BalanceYear))
            {
                this.YearList.Add(new InvestmentAccountBalance { BalanceYear = item.BalanceYear });
            }

            this.FilterChanged();
        }


        public void FilterChanged()
        {
            if (this.SelectedYear == 0)
            {
                this.SelectedYear = DateTime.Now.Year;
            }

            if (this.SelectedAccount == null)
            {
                this.SelectedAccount = this.AccountList[0];
            }

            if (this.SelectedAccount.InvestmentAccountId == 0)
            {
                this.AccountBalanceListFiltered = this.AccountBalanceList.Where(a => a.BalanceYear == this.SelectedYear).OrderByDescending(a => a.BalanceDate).ToList();
            }
            else
            {
                this.AccountBalanceListFiltered = this.AccountBalanceList.Where(a => a.BalanceYear == this.SelectedYear && a.InvestmentAccountId == this.SelectedAccount.InvestmentAccountId).OrderByDescending(a => a.BalanceDate).ToList();
            }

        }
Last modified: January 24, 2021

Author

Comments

Write a Reply or Comment