This is a migrated thread and some comments may be shown as answers.

Prefiltering the grid

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bradley
Top achievements
Rank 1
Bradley asked on 06 Feb 2019, 01:58 PM

     Good morning,

 

I'm working on an web application and I was wondering the best way to go about initializing a prefiltered grid. Users see a flowchart of different statuses of a product, if they click on one of the statuses I would like it to go to the grid that I have with the status column filtered with the status that they selected.

 

I thought the best way to do this would be to create a separate method in the controller for each status, but that seemed a little clunky. 

 

I currently have the status column as 

columns.Bound(c => c.Status).Width(150)
                       .Title("Status")
                          .Filterable(filterable => filterable
                                  .Cell(cell => cell
                                      .ShowOperators(false)
                                      .InputWidth(150)
                                      .Operator("contains")
                                      .SuggestionOperator(FilterType.Contains)
                                      .Template("statusFilter")
                                  )
                              );

 

function statusFilter (element) {
            element.element.kendoDropDownList({
                dataSource: {
                    dataType: "json",
                    transport: {
                        read: "@Url.Action("Status_Filter", "Controller")"
                    }
                },
                optionLabel: "--Select Status--"
            });
        }

 

Would I need to change how I have my filtering? Would you know how to do this?

 

2 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 11 Feb 2019, 07:30 AM
Hello Bradley,

A possible solution is to include a default filter for the Status field in the configuration of the DataSource.

e.g.

.DataSource(dataSource => dataSource
 
    .Ajax()
    ...
    .Filter(f=> {
        f.Add(a => a.Status).IsEqualTo(SomeValue);
    })
)


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Bradley
Top achievements
Rank 1
answered on 11 Feb 2019, 01:25 PM

Thank you for the reply. 

 

I posted another thread because I realized that I was going about this in the wrong way, and what you suggested is the way to go. I was having difficulty with with setting a default field as I wasn't able to assign a variable and place that for the value. I was able to get a ViewBag to work.

 

Thank you for your answer.

Tags
Grid
Asked by
Bradley
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Bradley
Top achievements
Rank 1
Share this question
or