I want to filter the list/library control using the Choice field. I haven't found an example of this scenario in the community so I thought I would ask.
Here is the code that I am working with but is not doing anything:
//Code will filter the List/Library Control based on Report_Type Choice field
var dt = fd.control('SPDataTable1');
dt.ready(function() {
filterDT();
});
//filter List or Library with new value when Search field changes
fd.field('Search').$on('change', function() {
filterDT();
});
function filterDT(){
if(fd.field('Search').value){
dt.filter = "<Eq><FieldRef Name='Report_Type'/><Value Type='Text'>"
+ fd.field('Search').value + "</Value></Eq>";
}
else{
dt.filter = '';
}
dt.refresh();
}
Dear @DryChips,
Is it a single choice or multi choice field? The code above should work for a single choice from the looks of it, but it will not for multi choice.
Also, it is the Report_Type the choice type field, right?
The field is a Single Choice field, I have tried using this but it doesn't seem to be working. It does look like its doing something in the background but nothing obvious.
Try using a static value in JS code instead of a search field value first. Once you get it working with static value, try replacing it with search field value.
Dear @Qman,
This doesn't give me anything, apart from the fact that the filter is not working properly. The important part is - what's the type of Report_Type field used in List or Library?
Not the DropDown1 you have on the form, but the Report_Type in another list.
Can you open Report_Type field column in list settings and show it to me?
Like this for Report_Type field:
The list/library is referencing the form's SharePoint List. The form will provide HR an ability to add/remove people from a SharePoint list as they will have access to the PowerBi repots.
fd.spRendered(function(){
//Code will filter the List/Library Control based on Report_Type Choice field
var dt = fd.control('SPDataTable1');
dt.ready(function() {
filterDT();
});
//filter List or Library with new value when Search field changes
fd.field('Report_Type').$on('change', function() {
filterDT();
});
function filterDT(){
if(fd.field('Report_Type').value){
dt.filter = "<Eq><FieldRef Name='Report_Type'/><Value Type='Text'>"
+ fd.field('Report_Type').value + "</Value></Eq>";
}
else{
dt.filter = '';
}
dt.refresh();
}
});
Video attached:
I've used the same Report_Type field for filtering, but it should work with Search field just as well.
My colleague @DryChips is thinking of creating an New and Edit version form into one form as only certain people will access this form. I will explain to her that a New and Edit version will need to be created for this functionality to work.
Ah, the reason why it didn't work was because of the function name. So simple. The function names need to be unique otherwise it will clash with each other.