Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleSample

Sample App that utilizes the BeanShell Binder to manually populate a list and apply a filter.

Code Block
titleGet Available Columns Script
import java.util.ArrayList;
import java.util.List;
import org.joget.apps.datalist.model.DataListColumn;


List columns = new ArrayList();
// add default metadata fields
columns.add(0, new DataListColumn("id", "id", true));
columns.add(0, new DataListColumn("name", "name", true));
columns.add(0, new DataListColumn("information", "information", true));
columns.add(0, new DataListColumn("category", "category", true));

return columns.toArray(new DataListColumn[0]);
Code Block
titleGet Data Rows Script
import org.joget.apps.datalist.model.DataListCollection;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.datalist.model.DataListFilterQueryObject;
import java.util.regex.Pattern;

DataListCollection resultList = new DataListCollection();
FormRowSet rowSet = null;
FormRow fr = null;

// Data 1
fr = new FormRow();
fr.setProperty("id", "example-id-1");
fr.setProperty("name", "example name 1");
fr.setProperty("information", "example information 1");
fr.setProperty("category", "example category 1");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 2
fr = new FormRow();
fr.setProperty("id", "example-id-2");
fr.setProperty("name", "example name 2");
fr.setProperty("information", "example information 2");
fr.setProperty("category", "example category 2");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 3
fr = new FormRow();
fr.setProperty("id", "example-id-3");
fr.setProperty("name", "joget");
fr.setProperty("information", "example information 3");
fr.setProperty("category", "example category 3");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

DataListFilterQueryObject obj = new DataListFilterQueryObject();
boolean isFiltered = false;
Collection values = new ArrayList();
DataListCollection filteredResultList = new DataListCollection();

        for (int i = 0; i < filterQueryObjects.length; i++) {
            if (filterQueryObjects[i].getValues() != null && filterQueryObjects[i].getValues().length > 0) {
                values.addAll(Arrays.asList(filterQueryObjects[i].getValues()));
                System.out.println("Arrays.asList(filterQueryObjects[i].getValues())----------->"+Arrays.asList(filterQueryObjects[i].getValues()));
            }
            
            for (s: resultList) {
                String targetColumn = s.getProperty("name");
                
                System.out.println("s----------->"+s);
                System.out.println("targetColumn----------->"+targetColumn);
                
                for (String searchWord : values) {
                    System.out.println("searchWord= " + searchWord);
                    
                    String searchWordReplaced = searchWord.replaceAll("%", "");
                    // Pattern pattern = Pattern.compile(searchWord);
                    
                    System.out.println("searchWordReplaced= " + searchWordReplaced);

                    if (targetColumn.contains(searchWordReplaced)) {
                        rowSet = new FormRowSet();
                        rowSet.add(s);
                        filteredResultList.addAll(rowSet);
                        isFiltered = true;
                   }
                }
            }
            if(isFiltered){
                return filteredResultList;
            }
        }
        if (values.size() > 0){
            obj.setValues((String[]) values.toArray(new String[0]));
        }



return resultList;
Code Block
titleGet Number of Total Data Rows Script
import org.joget.apps.datalist.model.DataListCollection;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.datalist.model.DataListFilterQueryObject;
import java.util.regex.Pattern;

DataListCollection resultList = new DataListCollection();
FormRowSet rowSet = null;
FormRow fr = null;


// Data 1
fr = new FormRow();
fr.setProperty("id", "example-id-1");
fr.setProperty("name", "example name 1");
fr.setProperty("information", "example information 1");
fr.setProperty("category", "example category 1");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 2
fr = new FormRow();
fr.setProperty("id", "example-id-2");
fr.setProperty("name", "example name 2");
fr.setProperty("information", "example information 2");
fr.setProperty("category", "example category 2");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 3
fr = new FormRow();
fr.setProperty("id", "example-id-3");
fr.setProperty("name", "joget");
fr.setProperty("information", "example information 3");
fr.setProperty("category", "example category 3");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

DataListFilterQueryObject obj = new DataListFilterQueryObject();
boolean isFiltered = false;
Collection values = new ArrayList();
DataListCollection filteredResultList = new DataListCollection();

        for (int i = 0; i < filterQueryObjects.length; i++) {
            if (filterQueryObjects[i].getValues() != null && filterQueryObjects[i].getValues().length > 0) {
                values.addAll(Arrays.asList(filterQueryObjects[i].getValues()));
                }System.out.println("Arrays.asList(filterQueryObjects[i].getValues())----------->"+Arrays.asList(filterQueryObjects[i].getValues()));
            }
            for (
            for (s: resultList) {
                String targetColumn = s.getProperty("name");
                
  for (String searchWord : values) {
         System.out.println("s----------->"+s);
           String searchWordReplaced = searchWord.replaceAll("%", "");   System.out.println("targetColumn----------->"+targetColumn);
                
                for (String searchWord : values) {
                    System.out.println("searchWord= " + searchWord);
                    
                    String searchWordReplaced = searchWord.replaceAll("%", "");
                    Pattern pattern = Pattern.compile(searchWord);
                    
                    System.out.println("searchWordReplaced= " + searchWordReplaced);

                    if (targetColumn.contains(searchWordReplaced)) {
                        rowSet = new FormRowSet();
                        rowSet.add(s);
                        filteredResultList.addAll(rowSet);
                        isFiltered = true;
                   }
                }
            }
            if(isFiltered){
     }
            }return filteredResultList.size();
            if(isFiltered){}
        }
        returnif filteredResultList(values.size() > 0);{
            obj.setValues((String[])  }values.toArray(new String[0]));
        }



return resultList.size();

...