Hello, I faced with problem with updating data in repeater. When user adds new item using the form, the new record is not displayed in repeater. If to reload the page, the record is updated:
After pressing button “Send”, the function loadMaterialButton_click starts working:
export async function loadMaterialButton_click(event) {
let loadResult = $w('#loadMaterialResult');
if($w("#uploadFileButton").value.length > 0)
{
$w("#uploadFileButton").startUpload()
.then( (uploadedFile) => {
let toInsert = {
"title": $w('#subjectInputField').value,
"mainCategory": $w('#mainCategoryMaterialsInProfile').value,
"subCategory": $w('#subCategoryMaterialsInProfile').value,
"documentUrl": uploadedFile.url
};
insertToDb("document_db", toInsert); //document_db is collection where the new item is saved
loadResult.text = "Upload successful";
loadResult.show();
resetLoadMaterialFields();
})
.catch( (uploadError) => {
resetLoadMaterialFields();
loadResult.text = "File upload error";
loadResult.show();
console.log("File upload error: " + uploadError.errorCode);
console.log(uploadError.errorDescription);
});
}
}
The function insertToDb saves the new item to collection and refresh dataset (dataset is connected to document_db is collection):
async function insertToDb(db, itemToInsert)
{
wixData.save(db, itemToInsert);
$w("#documentDbInProfile").onAfterSave( () => {
$w("#documentDbInProfile").refresh();
let page = $w("#paginationForUserMaterials").currentPage;
let skipCount = (page - 1) * 10;
getMaterialsByCurrentUserId(skipCount, 10);
})
}
The function getMaterialsByCurrentUserId sends request with query and update repeater:
async function getMaterialsByCurrentUserId(skipNumber, numberLimit){
let query = wixData.query("document_db")
.eq("_owner", wixUsers .currentUser. id) //here I set currentUser. id
.skip(skipNumber)
.limit(numberLimit)
.descending("_createdDate");
let res = await query
.find()
.then((result) => {
$w('#repeaterUserMaterials').data = result.items;
$w('#repeaterUserMaterials').onItemReady(($item, itemData, index) => {
$item("#titleText").text = itemData.title;
$item("#mainCategoryText").text = itemData.mainCategory;
$item("#subCategoryText").text = itemData.subCategory;
})
});
}
Could you help me to solve this issue. Thanks in advance.