on 2022 Nov 23 11:47 AM
Hello experts, I have a problem that I don't know how to solve:
I'm developing an application in which documents are filtered based on the date entered in the DatePicker. The problem is that in the db schema "DocumentDate" is of type string, and this type cannot be changed (in the db); I would then need to take the date, convert it to type Date and then apply the filter.
Surely something escapes me, but I do not know how I should do exactly. Below is the code.
Thanks everyone for your time.
Controller.js
///DatePicker////
var dateFrom = this.dateFromFilter.getDateValue();
var dateTo = this.dateToFilter.getDateValue();
var PathValue = "DocumentDate";
if (dateFrom && dateTo) {
console.log("BT");
aFilters.push(new sap.ui.model.Filter({
path: PathValue,
test: function(oValue)
{
oValue=new Date(oValue);
return (dateFrom<=oValue && oValue<=dateTo)
}
}));
} else if (dateFrom) {
console.log("GE");
aFilters.push(new sap.ui.model.Filter({
path: PathValue,
test: function(oValue)
{
oValue=new Date(oValue);
return dateFrom<=oValue;
}
}));
} else if (dateTo) {
console.log("LE");
aFilters.push(new sap.ui.model.Filter({
path: PathValue,
test: function(oValue)
{
oValue=new Date(oValue)
return oValue<=dateTo;
}
}));
}
oTable.getBinding("items").filter(aFilters);
.xml
<DatePicker id="DatePicker_Start"
displayFormat="short"
class="multiInputMaxWidth"/>
DocumentHeader.csv
DOCUMENTID;STATUS;TOTALVALUE;CURRENCY;TOTALQUANTITY;DOCUMENTDATE;CUSTOMERORDER;REQUESTDELIVERYDATE;EFFECTIVEDELIVERYDATE;DELIVERYSTATUS;DELIVERYBLOCK;INVOICEBLOCK;PAYCONDITIONS;CustomerId_CustomerId;ShipToPartnerId_CustomerId
0000000001;STATUS9518;9649.76;CURRENCY7984;4510.45;01/01/2000;CUSTOMERORDER4967;REQUESTDELIVERYDATE2700;EFFECTIVEDELIVERYDATE4377;DELIVERYSTATUS3174;DELIVERYBLOC9207;INCOICEBLOC7690;PAYCONDITIONS8851;0000000001;0000000003
0000000002;STATUS2036;6191.53;CURRENCY8515;3169.44;01/01/2010;CUSTOMERORDER8183;REQUESTDELIVERYDATE7473;EFFECTIVEDELIVERYDATE3749;DELIVERYSTATUS4674;DELIVERYBLOC6190;INCOICEBLOC121;PAYCONDITIONS5183;0000000002;0000000002
0000000003;STATUS9479;9783.38;CURRENCY3920;1446.79;01/01/1990;CUSTOMERORDER2476;REQUESTDELIVERYDATE3081;EFFECTIVEDELIVERYDATE129;DELIVERYSTATUS3606;DELIVERYBLOC5509;INCOICEBLOC2220;PAYCONDITIONS1751;0000000002;0000000004
Schema.cds
entity DocumentHeader
{
key DocumentId : String(100)
@Core.Computed;
Status : String(100);
TotalValue : Double;
Currency : String(100);
TotalQuantity : Double;
DocumentDate : String(100);
CustomerOrder : String(100);
RequestDeliveryDate : String(100);
EffectiveDeliveryDate : String(100);
DeliveryStatus : String(100);
DeliveryBlock : String(100);
InvoiceBlock : String(100);
PayConditions : String(100);
CustomerId : Association to one Customer;
ShipToPartnerId : Association to one Customer;
to_DocumentItems : Association to many DocumentItem on to_DocumentItems.DocumentId = $self;
to_PriceConditions : Association to many PriceCondition on to_PriceConditions.DocumentId = $self;
to_Partners : Association to many Partner on to_Partners.DocumentId = $self;
to_Notes : Association to many Note on to_Notes.DocumentId = $self;
}
Some screen:
This is my solution
FilterTokens.forEach((token) => {
aFilters.push(
new Filter({
path: 'to_DocumentItems',
operator: 'Any',
variable: 'item',
condition: new Filter({
path: 'item/ProductId_ProductId',
operator: "EQ",
value1: token.getKey(),
})
})
);
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
73 | |
10 | |
9 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.