See the code below, but first some explanations could be helpfull.
On one page, I have 3 sections.
Section 1 : a wix table object displaying a list of tickets (through a dateset), with 3 checkboxes representing the 3 states of a ticket ( New, IN progress, Closed). A filter is applied to the dateset reflecting the choices (see code Applyfilter). By default New and in progress are checked, CLosed is unchecked and section 2 and 3 are hidden/collapsed.
Further to some sorting capabilities, there are 2 processes linked to the question.
Process 1 : doubble click on a line of the table brings the user to section 2 Modify the selected line. Sections 1 and 3 are hidden/collapsed (see switch selection)
Process 2 : click on a button “Add a ticket” that brings to section 3. Sections 1 and 2 are hidden/collapsed (see switch selection)
Process 1 : a repeater linked to the same dataset as the table. a save button (see code button_update)
Process 2 : some input fields and an insert record process directly to the collection (not through to dataset). A save button (see button_create)
THE PROBLEM
scenario :
- CHeckbox “closed” is not checked, so only new and in progress tickets are visible
- doubble click on one line to make some modifications, and to change status to “closed”
- save the modification
result :
- the table is updated with the modification made, but the line is still visible, although it status is closed !!! The filter has not been modified, so I thought it is still valid ans the closed line should not appear.
Bottun update
export function buttonupdate_click(event) {
$w("#datasetAnomalie").save()
.then((item) => {
console.log("item");
console.log(item);
})
.catch((err) => {
let errMsg = err;
console.log("ErrMsg");
console.log(errMsg);
});
SwitchSections("2List");
}
Button create
export function buttonCreate_click(event) {
console.log($w(‘#textBoxCmntCreate’).value)
// check if comments filled in
//several checks…
} else {
// prepare fr insert
let toInsert = {
"emailUser": $w('#inputEmail').value,
"refPnj": $w('#inputJPN').value,
"refPiquet": $w('#inputPi').value,
"refPanneau": $w('#inputPi').value,
"Statut": "Nouveau",
"origin": "Gestion",
"fieldComment": $w('#textBoxCmntCreate').value
};
wixData.insert("PNUserMsg", toInsert)
.then((item) => {
console.log(item);
//refresh dataset
$w("#datasetAnomalie").refresh();
SwitchSections("2List");
})
.catch((err) => {
console.log(err);
});
}
}
switch selection
function SwitchSections(Way) {
switch (Way) {
case “2Modify”:
// show detail & mantenance
$w(‘#sectionModify’).show();
$w(‘#sectionModify’).expand();
// goto detail tab
$w(‘#tabs1’).changeTab($w(“#tabs1”).defaultTab);
// hide List and create
$w(‘#sectionList’).hide();
$w(‘#sectionList’).collapse();
$w(‘#sectionCreate’).hide();
$w(‘#sectionCreate’).collapse();
break;
case "2List":
// hide Modify and Create
$w('#sectionModify').hide();
$w('#sectionModify').collapse();
$w('#sectionCreate').hide();
$w('#sectionCreate').collapse();
// show list
$w('#sectionList').show();
$w('#sectionList').expand();
break;
case "2Create":
// hide Modify and Create
$w('#sectionModify').hide();
$w('#sectionModify').collapse();
$w('#sectionList').hide();
$w('#sectionList').collapse();
// show list
$w('#sectionCreate').show();
$w('#sectionCreate').expand();
break;
}
}
ApplyFilters
function ApplyFilters() {
// initialise filter
// look which filter requested
if ($w(‘#checkboxclosed’).checked && $w(‘#checkboxNew’).checked &&
$w(‘#checkboxInprogress’).checked && $w(‘#checkboxCanceled’).checked) {
// everything is needed; so empty filter
console.log("everything checked");
$w('#datasetAnomalie').setFilter(WixData.filter());
} else {
// at least one checkbox checked, generate list for filter
let MyFilter = []
if ($w('#checkboxclosed').checked) {
MyFilter.push("Clôturé") // closed
}
if ($w('#checkboxNew').checked) {
MyFilter.push("Nouveau") //New
}
if ($w('#checkboxInprogress').checked) {
MyFilter.push("En cours") //In progress
}
console.log(MyFilter);
$w("#datasetAnomalie").setFilter(WixData.filter()
.hasSome("Statut", MyFilter)
)
// to develop later : what to do if no check box checked. NO emergency
console.log("direct count " + $w("#datasetAnomalie").getTotalCount());
}
}