Xpages search between 2 dates

2019-01-20 15:32发布

问题:

I have a view with some data, and a column with the creation date of each document. I want to make a search feature with 3 input fields: Name, StartDate, EndDate. The result of the search should be all the documents with the same name and within the 2 dates.

Can anyone help me?

Thanks

回答1:

Use the search property of DominoView data source. It does a full text search on all documents in view. Create a search string like

[Name]="Meier" AND [_creationDate]>=12-01-2013 AND [_creationDate]<=30-08-2014

Your data source code would look like this:

    <xp:this.data>
        <xp:dominoView
            var="view1"
            viewName="YourView">
            <xp:this.search><![CDATA[#{javascript:
            var search = "";
            var formatter = new java.text.SimpleDateFormat("dd-MM-yyyy");
            if (viewScope.Name) {
                search += ' AND [Name]="' + viewScope.Name + '*"';
            }
            if (viewScope.StartDate) {
                search += ' AND [_creationDate]>=' + formatter.format(viewScope.StartDate);
            }
            if (viewScope.EndDate) {
                search += ' AND [_creationDate]<=' + formatter.format(viewScope.EndDate);
            }
            return search.substring(5);}]]></xp:this.search>
        </xp:dominoView>
    </xp:this.data>

This code assumes that there are editable search fields which value is bound to viewScope.Name, viewScope.StartDate and viewScope.EndDate e.g.

<xp:inputText
    id="inputText1"
    value="#{viewScope.Name}">
</xp:inputText>

<xp:inputText
    id="inputText2"
    value="#{viewScope.StartDate}">
    <xp:this.converter>
        <xp:convertDateTime
            type="date"
            dateStyle="short">
        </xp:convertDateTime>
    </xp:this.converter>
    <xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText>