AND Filter is not working.
Filter is applied on both selected date and selected value from Combo box.
var oVal=this.getView().byId("idUser").getValue();
var dDateStart = oEvent.getSource().getProperty('dateValue');
var dDateEnd = new Date(dDateStart + 1);
var isValidDate = oEvent.getParameter("valid");
var aFilters = [];
dDateStart.setMilliseconds(0);
dDateStart.setSeconds(0);
dDateStart.setMinutes(0);
dDateStart.setHours(0);
dDateEnd.setMilliseconds(0);
dDateEnd.setSeconds(59);
dDateEnd.setMinutes(59);
dDateEnd.setHours(23);
aFilters=[new sap.ui.model.Filter("CreatedBy",sap.ui.model.FilterOperator.EQ, oVal),
new sap.ui.model.Filter("CrDate", sap.ui.model.FilterOperator.BT, dDateStart, dDateEnd)];
var oFilter = new sap.ui.model.Filter({
filters: aFilters,
and: true });
this.getView().byId("idCoTable").getBinding("items").filter(oFilter,true);
It is resolved.
Issue is with filtering with value instead of Key.
Thanks
Related
I'm developing a word addin that pulls xml data from our servers and binds it to a rich text content control. The user should only be able to format the data within the content control but can't edit or delete the data.
This is the code i've been able to come up with but it's not working..
var ooxmlPackage = new DOMParser().parseFromString(
'<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"></pkg:package>',
"text/xml"
);
var ooxmlPart = ooxmlPackage.createElement("pkg:part");
ooxmlPart.setAttribute("pkg:name", "/_rels/.rels");
ooxmlPart.setAttribute("pkg:contentType", "application/vnd.openxmlformats-package.relationships+xml");
ooxmlPart.setAttribute("pkg:padding", "512");
var ooxmlxmlData = ooxmlPackage.createElement("pkg:xmlData");
var ooxmlRelationships = ooxmlPackage.createElement("Relationships");
ooxmlRelationships.setAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/relationships");
var ooxmlRelationship = ooxmlPackage.createElement("Relationship");
ooxmlRelationship.setAttribute("Id", "rId1"); //TODO: generate unique ID
ooxmlRelationship.setAttribute(
"Type",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
);
ooxmlRelationship.setAttribute("Target", "word/document.xml");
ooxmlRelationships.appendChild(ooxmlRelationship);
ooxmlxmlData.appendChild(ooxmlRelationships);
ooxmlPart.appendChild(ooxmlxmlData);
var ooxmlDocPart = ooxmlPackage.createElement("pkg:part");
ooxmlDocPart.setAttribute("pkg:name", "/word/document.xml");
ooxmlDocPart.setAttribute(
"pkg:contentType",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"
);
var ooxmlDocPartxmlData = ooxmlPackage.createElement("pkg:xmlData");
var ooxmlDocument = ooxmlPackage.createElement("w:document");
ooxmlDocument.setAttribute("xmlns:w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
ooxmlDocument.setAttribute("xmlns:w15", "http://schemas.microsoft.com/office/word/2012/wordml");
var ooxmlDocumentBody = ooxmlPackage.createElement("w:body");
var ooxmlDocumentParagraph1 = ooxmlPackage.createElement("w:p");
var ooxmlContentControl = ooxmlPackage.createElement("w:sdt");
var sdtPr = ooxmlPackage.createElement("w:sdtPr");
//var lk = ooxmlPackage.createElement("w:lock");
//lk.setAttribute("w:val", "sdtContentLocked");
//sdtPr.appendChild(lk);
var alias = ooxmlPackage.createElement("w:alias");
alias.setAttribute("w:val", "MyControl");
sdtPr.appendChild(alias);
var id1 = ooxmlPackage.createElement("w:id");
id1.setAttribute("w:val", "1382295294");
sdtPr.appendChild(id1);
//var appr = ooxmlPackage.createElement("w15:appearance");
//appr.setAttribute("w15:val", "hidden");
//sdtPr.appendChild(appr);
sdtPr.appendChild(ooxmlPackage.createElement("w:showingPlcHdr"));
//var plchdlr = ooxmlPackage.createElement("w:placeholder");
//var docPrt = ooxmlPackage.createElement("docPart");
//docPrt.setAttribute("w:val", "defaultPlaceHolder_-1854013440");
//plchdlr.appendChild(docPrt);
//sdtPr.appendChild(plchdlr);
var bindingNode = ooxmlPackage.createElement("w15:dataBinding");
//bindingNode.setAttribute("w:prefixMappings","xmlns:ns0='custom'");
bindingNode.setAttribute("w:xpath","/Root[1]/Node[1]");
bindingNode.setAttribute("w:storeItemID", "{C2F77B86-6131-4922-803B-54FACB654C16}");
sdtPr.appendChild(bindingNode);
ooxmlContentControl.appendChild(sdtPr);
var sdtContent = ooxmlPackage.createElement("w:sdtContent");
var parag = ooxmlPackage.createElement("w:p");
var r = ooxmlPackage.createElement("w:r")
var t = ooxmlPackage.createElement("w:t")
//t.innerHTML= '[This is a test]';
r.appendChild(t);
parag.appendChild(r);
sdtContent.appendChild(parag);
ooxmlContentControl.appendChild(sdtContent);
ooxmlDocumentBody.appendChild(ooxmlDocumentParagraph1);
ooxmlDocumentBody.appendChild(ooxmlContentControl);
ooxmlDocument.appendChild(ooxmlDocumentBody);
ooxmlDocPartxmlData.appendChild(ooxmlDocument);
ooxmlDocPart.appendChild(ooxmlDocPartxmlData);
ooxmlPackage.documentElement.appendChild(ooxmlPart);
ooxmlPackage.documentElement.appendChild(ooxmlDocPart);
var serializer = new XMLSerializer();
var ooxmlPackageString = serializer.serializeToString(ooxmlPackage);
console.log(ooxmlPackageString);
Office.context.document.setSelectedDataAsync(ooxmlPackageString, { coercionType: "ooxml" });
Office.context.document.customXmlParts.getByIdAsync(
'<Root xmlns=""> <Node>VALUE1</Node></root>',
function (result) { });
It just inserts an empty content control when it runs, it doesn't map the xml node data as expected.
I have written code for search fields in ui5 controllers files, But the search field is not giving expected output when I pasted particular column value in input search field. Instead if I type the value in search field it is giving exact output.
I have used livechange event. I also tried with search event but unable to get the output.
I am using odata services.
Below is the controller file code:
onSearch: function(oEvt) {
// add filter for search
var aFilters = [];
var sQuery = oEvt.getSource().getValue();
if (sQuery && sQuery.length > 0) {
var filter = new Filter("UNIQUE_ID", sap.ui.model.FilterOperator.EQ, sQuery);
aFilters.push(filter);
}
// update list binding
var list = this.byId("orderTable");
var binding = list.getBinding("items");
binding.filter(aFilters);
}
View code:
Label class="sapUiMediumMarginTop" text="Unique Id"
SearchField width="150px" class="sapUiSmallMargin" liveChange="onSearch"
Please suggest me if I am missing anything.
Maybe this example can help you out? I tested your code with some random data and it worked for me.
onSearch: function(oEvent) {
var sQuery = oEvent.getParameter("query");
var oFilter1 = new Filter("Name", FilterOperator.Contains, sQuery);
var oFilter2 = new Filter("Age", FilterOperator.Contains, sQuery);
var arrFilter = new Filter([oFilter1, oFilter2], false);
// filter binding
var oList = this.byId("idList");
var oBinding = oList.getBinding("items");
oBinding.filter(arrFilter);
},
I have a table.a column consists of input fields. How can I get value from searchHelpDialog to table item?
Below is a sample table:
And the value help dialog:
You can add the id of the field as custom data to your value help dialog.
You can get the id from the oEvent.
openValueHelpDialog: function(oEvent) {
var oDialog = sap.ui.xmlfragment();
var oField = new sap.ui.core.CustomData();
oField.setKey("field");
oField.setValue(oEvent.getParameter("id"));
oDialog.addCustomData(oField);
oDialog.open();
}`
In the handleConfirm function you can then set value into the field with the id from the custom data:
handleConfirm: function(oEvent) {
var sFieldId = oEvent.getSource().data("field");
var oField = this.getView().byId(sFieldId);
var sSelectedValue = oEvent.getParameter("selectedItem");
oField.setValue(sSelectedValue);
}
you could use a datamodel, in which the value is written when selected.
this would need to happen in the controller of the fragment you use to build the searchHelpDialog.
also the model needs to be generated, since the rows of your list probably aren't static.
Thanks friends.
Problem solved.Code;
_handleValueHelp: function(oEvent) {
this.selectedValueHelp = oEvent.getSource();
}
_handleValueHelpClose: function(oEvent) {
var oSelectedItem = oEvent.getParameter("selectedItem");
if (oSelectedItem) {
this.selectedValueHelp.setValue(oSelectedItem.getTitle());
var productInput = this.getView().byId("helpvalue");
productInput.setValue(oSelectedItem.getTitle());
}
}
I have come across with situation where more than 10 input values has to be passed to back end as filters. Is there any other option to create and pass filters instead of creating it in controller for each input filed?
If you want to have more sophisticated way of controlling the filter stuff declaratively via the XML view, for example, you can go with the following approach:
Assign to all the affected inputs a "customData" property, defining the "filterProperty" and "filterOperation"
Assign to all affected inputs the same "fieldGroupId"
On the filter button trigger, grab all the input via the "getControlsByFieldGroupId" method and construct the filters using the custom data form each input via the "data" function call
for using custom data include the namespace to the view:
xmlns:data="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
customData doc
in XML:
<Input fieldGroupIds="InputGroup" data:filterName="Id" data:filterOperation="EQ" />
<Input fieldGroupIds="InputGroup" data:filterName="Name" data:filterOperation="Constains" />
<Input fieldGroupIds="InputGroup" data:filterName="Color" data:filterOperation="LT" />
in JS:
var aInputs = oView.getControlsByFieldGroupId("InputGroup");
var aFilters = aInputs.map(function(oInput) {
var sFilterName = oInput.data("filterName");
var sFilterOperation = oInput.data("filterOperation");
return new Filter(sFilterName, sFilterOperation, oInput.getValue());
});
See example
You can create filter for every input and push it to the array of filters which you will use as you need.
E.g.:
var oFilter1 = new sap.ui.model.Filter("Input1", sap.ui.model.FilterOperator.Contains, value1);
var oFilter2 = new sap.ui.model.Filter("Input2", sap.ui.model.FilterOperator.Contains, value2);
var oFilter3 = new sap.ui.model.Filter("Input3", sap.ui.model.FilterOperator.Contains, value3);
var oFilter4 = new sap.ui.model.Filter("Input4", sap.ui.model.FilterOperator.Contains, value4);
var allFilters = new sap.ui.model.Filter([oFilter1, oFilter2, oFilter3, oFilter4], false);
For more info look here.
//Create an array
var aFilters = [];
if (yourVal1) {
aFilters.push(new sap.ui.model.Filter("Dimension", sap.ui.model.FilterOperator.EQ, yourVal1));
}
if (yourVal2) {
aFilters.push(new sap.ui.model.Filter("Language", sap.ui.model.FilterOperator.EQ, yourVal1));
}
this.getModel().read("/YourEntitySet", {
filters: aFilters,
success: function(oData) {
// use the response as required.
},
error: function() {
}
});
I am working on an odata fiori app & I want to filter my list depending on two parameters and not just one : "Mpobj" & "Atinn", so i tried this code :
_onObjectMatched: function(oEvent) {
var sObjectPath = oEvent.getParameter("arguments").infosId;
var sObjectPath1 = oEvent.getParameter("arguments").objectI;
var oView = this.getView();
oView.bindElement(sObjectPath, sObjectPath1);
var frag = this.getView().byId("tableid1");
var oFilter = new sap.ui.model.Filter("Mpobj", sap.ui.model.FilterOperator.Contains, sObjectPath);
var oFilter1 = new sap.ui.model.Filter("Atinn", sap.ui.model.FilterOperator.Contains, sObjectPath1);
frag.bindElement("Infos" + "/mesureSet").getBinding("items").filter([oFilter], [oFilter1]);
},
But when i debugg, it appears that he's reading the first parameter "Mpobj" but doesn't recognize the second one "Atinn".
Any suggestions ?
You should use just one array. Try the following
var aFilters=[];
var oFilter = new sap.ui.model.Filter("Mpobj", sap.ui.model.FilterOperator.Contains, sObjectPath);
aFilters.push(oFilter);
var oFilter1 = new sap.ui.model.Filter("Atinn", sap.ui.model.FilterOperator.Contains, sObjectPath1);
aFilters.push(oFilter1);
frag.bindElement("Infos" + "/mesureSet").getBinding("items").filter(aFilters);