根据表中的单元格,滤波器可以显示动态表

发布于 2025-02-01 08:29:51 字数 1823 浏览 0 评论 0原文

我的前端有一个桌子,上面有3列和3行。

我想使单元单元可单击,并根据其点击的滤镜显示带有过滤器的表。

我有一个列表,我想根据点击的内容来应用过滤器。 我该怎么做?

+-------+----------+----------+----------+
|       | Col 1    | Col 2    | Col 3    |
+=======+==========+==========+==========+
| Row 1 | Item 1-1 | Item 2-1 | Item 3-1 |
+-------+----------+----------+----------+
| Row 2 | Item 1-2 | Item 2-2 | Item 3-2 |
+-------+----------+----------+----------+
| Row 3 | Item 1-3 | Item 2-3 | Item 3-3 |
+-------+----------+----------+----------+

例如

MyList = await GetMyList();

​只有当applyEname ='xx'或glperiodname ='yy' 我该怎么做?

目前,我有这个(正在显示整个列表):

@if (Model.MyList?.First() is not null)
{
    <h2>Expenditures</h2>
    <table class="table">
        <thead>
        <tr>
            <th>Task Number</th>
            <th>Employee Name</th>
            <th>Employee Number</th>
            <th>GL Period Name</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var expenditure in Model.MyList)
        {
            <tr>
                <td>@expenditure.TaskNumber</td>
                <td>@expenditure.EmployeeName</td>
                <td>@expenditure.EmployeeNumber</td>
                <td>@expenditure.GlPeriodName</td>
            </tr>
        }
        </tbody>
    </table>
}

我知道我可以用model.mylist.mylist.mylist.(x =&gt; x.parameter = filter)过滤,但是如何根据单击的内容来传递此参数条件上表中单击哪一行?
由于过滤器每次都不会相同,例如:

如果他们单击项目1-1,我想要的

Model.MyList.Where(x => x.parameterX = valueX)

,如果他们单击项目1-2:

Model.MyList.Where(x => x.parameterY = valueXY)

I have a table in my front end that has 3 columns and 3 rows.

I want to make the cells clickable and for this to show below a table with filters according to what they clicked.

I have a list to which I would like to apply the filters based on what was clicked.
how could I do this?

+-------+----------+----------+----------+
|       | Col 1    | Col 2    | Col 3    |
+=======+==========+==========+==========+
| Row 1 | Item 1-1 | Item 2-1 | Item 3-1 |
+-------+----------+----------+----------+
| Row 2 | Item 1-2 | Item 2-2 | Item 3-2 |
+-------+----------+----------+----------+
| Row 3 | Item 1-3 | Item 2-3 | Item 3-3 |
+-------+----------+----------+----------+

I have

MyList = await GetMyList();

I want that when I click on "Item 1-1" for example, to get below a table with a filter applied to MyList according to the conditions I want for this case (the filters would be different for each cell) such as only when EmployeeName = 'XX' or GlPeriodName = 'YY'
how could I do this?

currently I have this (which is showing the entire list):

@if (Model.MyList?.First() is not null)
{
    <h2>Expenditures</h2>
    <table class="table">
        <thead>
        <tr>
            <th>Task Number</th>
            <th>Employee Name</th>
            <th>Employee Number</th>
            <th>GL Period Name</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var expenditure in Model.MyList)
        {
            <tr>
                <td>@expenditure.TaskNumber</td>
                <td>@expenditure.EmployeeName</td>
                <td>@expenditure.EmployeeNumber</td>
                <td>@expenditure.GlPeriodName</td>
            </tr>
        }
        </tbody>
    </table>
}

I understand I can filter with Model.MyList.Where(x => x.parameter = filter), but how do I pass this parameter condition based on what is clicked on what row is clicked in the upper table?
being that the filter is not going to be the same every time such as:

if they click Item 1-1 I want

Model.MyList.Where(x => x.parameterX = valueX)

and if they click Item 1-2:

Model.MyList.Where(x => x.parameterY = valueXY)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒灬来后我 2025-02-08 08:29:51

您可以将表单元格值作为锚点链接,并使用asp-route- {value}传递参数值。

这是一个简单的演示:

@page
@model IndexModel
<table class="table">
    <thead>
        <tr>Col1</tr>
        <tr>Col2</tr>
        <tr>Col3</tr>
    </thead>
    <tbody>
        <tr>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="aa">Item 1-1</a></td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="bb">Item 2-1</a></td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="cc">Item 3-1</a></td>
        </tr>
        <tr>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-glPeriodName ="dd">Item 1-2</a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-glPeriodName="ee">Item 2-2</a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-glPeriodName="ff">Item 3-2</a> </td>
        </tr>
        <tr>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="gg">Item 1-3 </a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="hh">Item 2-3 </a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="ii">Item 3-3 </a></td>
        </tr>
    </tbody>
</table>
@if (Model.MyList!=null)         //it is better to change here in case of null exception.....
{
    <h2>Expenditures</h2>
    <table class="table">
        <thead>
        <tr>
            <th>Task Number</th>
            <th>Employee Name</th>
            <th>Employee Number</th>
            <th>GL Period Name</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var expenditure in Model.MyList)
        {
            <tr>
                <td>@expenditure.TaskNumber</td>
                <td>@expenditure.EmployeeName</td>
                <td>@expenditure.EmployeeNumber</td>
                <td>@expenditure.GlPeriodName</td>
            </tr>
        }
        </tbody>
    </table>
}

PageModel:

public class IndexModel : PageModel
{
   //for easy testing, I just hard coded.....
    public List<TestVM> MyList { get; set; }=new List<TestVM>()
    {
            new TestVM() { EmployeeName = "aa",EmployeeNumber = "1001",GlPeriodName = "dd",TaskNumber = "task1"},
            new TestVM() { EmployeeName = "bb",EmployeeNumber = "1002",GlPeriodName = "ee",TaskNumber = "task2"}
    };
      
    public void OnGetSpecificEmployee(string employeeName,string glPeriodName)
    {
        if(!string.IsNullOrEmpty(employeeName))
            MyList = MyList.Where(a=>a.EmployeeName.Equals(employeeName)).ToList();
        if(!string.IsNullOrEmpty(glPeriodName))
            MyList = MyList.Where(a => a.GlPeriodName.Equals(glPeriodName)).ToList();
    }

    public void OnGet()
    {

    }
}

You can make the table cell value as an anchor link and use asp-route-{value} to pass the parameter value.

Here is a simple demo:

@page
@model IndexModel
<table class="table">
    <thead>
        <tr>Col1</tr>
        <tr>Col2</tr>
        <tr>Col3</tr>
    </thead>
    <tbody>
        <tr>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="aa">Item 1-1</a></td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="bb">Item 2-1</a></td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="cc">Item 3-1</a></td>
        </tr>
        <tr>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-glPeriodName ="dd">Item 1-2</a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-glPeriodName="ee">Item 2-2</a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-glPeriodName="ff">Item 3-2</a> </td>
        </tr>
        <tr>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="gg">Item 1-3 </a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="hh">Item 2-3 </a> </td>
            <td><a asp-page="Index" asp-page-handler="SpecificEmployee" asp-route-employeeName="ii">Item 3-3 </a></td>
        </tr>
    </tbody>
</table>
@if (Model.MyList!=null)         //it is better to change here in case of null exception.....
{
    <h2>Expenditures</h2>
    <table class="table">
        <thead>
        <tr>
            <th>Task Number</th>
            <th>Employee Name</th>
            <th>Employee Number</th>
            <th>GL Period Name</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var expenditure in Model.MyList)
        {
            <tr>
                <td>@expenditure.TaskNumber</td>
                <td>@expenditure.EmployeeName</td>
                <td>@expenditure.EmployeeNumber</td>
                <td>@expenditure.GlPeriodName</td>
            </tr>
        }
        </tbody>
    </table>
}

PageModel:

public class IndexModel : PageModel
{
   //for easy testing, I just hard coded.....
    public List<TestVM> MyList { get; set; }=new List<TestVM>()
    {
            new TestVM() { EmployeeName = "aa",EmployeeNumber = "1001",GlPeriodName = "dd",TaskNumber = "task1"},
            new TestVM() { EmployeeName = "bb",EmployeeNumber = "1002",GlPeriodName = "ee",TaskNumber = "task2"}
    };
      
    public void OnGetSpecificEmployee(string employeeName,string glPeriodName)
    {
        if(!string.IsNullOrEmpty(employeeName))
            MyList = MyList.Where(a=>a.EmployeeName.Equals(employeeName)).ToList();
        if(!string.IsNullOrEmpty(glPeriodName))
            MyList = MyList.Where(a => a.GlPeriodName.Equals(glPeriodName)).ToList();
    }

    public void OnGet()
    {

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文