Hello all,
I've been trying to work out how to filter a Library control by a field only which in this case is Title field on Edit mode (Form). Before that, to put into context, I have created a List (for item creation) and a Library (for stored documents/files). When an item is created in List, it triggers the Automate to create its folder (by Title) based on Parent ID in the Library. Then, on Edit mode, I want to upload any document in any format and save it upon clicking Save button.
The issue now here, during Edit mode and at the initial state of Library, all created folders are visible and some additional files with different format (testing) are shown and visible as expected. When I try to search a specific folder item by Title via filtering in a Search function, it seems working as fine. But when the textfield (string) is EMPTY, it returns to the initial state but some documents are missing and not visible. Some uploaded files from existing folders are also not visible except files with .pptx format. This is what is confusing me. I'm not sure what I am missing in my code. I followed from the documentation and tweaked around a little bit. But it didn't produce the result that I wanted.
Here is a sample the code I used:
fd.spRendered(() => {
console.log('Rendered!');
// declare variable for library control.
var dt = fd.control('SPDataTable1');
dt.ready().then(() => {
let textValueOnReady02 = !fd.field('SearchFilter1').value;
console.log(textValueOnReady02);
dt.refresh();
// when Search field is empty, do nothing, else, filter item by Title.
if (textValueOnReady02) {
console.log("Search field [textValueOnReady] === empty");
} else {
console.log("Search field [textValueOnReady] === NOT empty");
filterDT();
}
});
// filter Shared Library with new value when Search field changes.
fd.field('SearchFilter1').$on('change', () => {
let textValueOnChange02 = !fd.field('SearchFilter1').value;
console.log(textValueOnChange02);
if (textValueOnChange02) {
console.log("Search field [textValueOnChange] === empty");
dt.refresh();
} else {
console.log("Search field [textValueOnChange] === NOT empty");
filterDT();
}
});
const filterDT = () => {
console.log("filterDT");
dt.filter = "<Contains><FieldRef Name='Title'/><Value Type='Text'>"
+ fd.field('SearchFilter1').value + "</Value></Contains>";
dt.refresh();
}
});
Attached screenshots are as follows:
-
List
-
Library (storing files)
-
Item Test08 & its stored documents - before search/filter
-
Item Test09 - before search/filter
-
Item Test10 - before search/filter
-
Library content before search/filter at initial state
-
Library content changed after filtering
-
Library content - some files not shown when textfield is empty but .pptx files
-
Item Test08 - files not visible
-
Item Test09 - files not visible
-
Item Test10 - only 1 is visible for .pptx file
So, can anyone please help me how do I work this out? What did I actually miss here.
- How can I filter content in Library by Title field via Search function and make sure all format of files are visible upon filtering?
- In my code, there's a if else statement. How can I return the content in Library as before when Search field is empty then display all documents or else filter it as it is?
Appreciate your guidance. Thanks.