Replies: 11 comments
-
hmm I'm not sure to fully understand the use case, would it be possible to provide some kind of code/data sample? I'm open for contributions if you can provide a bit more demo/code to explain the use case that'd be great too |
Beta Was this translation helpful? Give feedback.
-
Sure, I'll try, but setting up a codebox, fiddler etc. is kinda cumbersome with an OData service and all that. So I'll try it with some insights and references from my tests and findings. Image you have an OData-bound grid with pagination, sorting and filtering. Due to the in-place editing feature, pagination, resorting, filtering etc. is currently not prevented, although there might be unsaved changes (which are stored in an edit queue). So whenever the user navigates, filters etc., the changes disappear from the UI (still in the edit queue) without giving the user the opportunity to persist those changes beforehand. E.g. if I use the default pagination service and component, clicking the "Next Page" button is not directly interceptable or the pagination changes would have to be reverted at a later point ( slickgrid-universal/packages/common/src/services/pagination.service.ts Lines 189 to 195 in 20564a3 Clicking on a column header for sorting is handled directly within function setupColumnSort() {
$headers.click(function (e) {
if (columnResizeDragging) return;
// temporary workaround for a bug in jQuery 1.7.1 (http://bugs.jquery.com/ticket/11328)
e.metaKey = e.metaKey || e.ctrlKey;
if ($(e.target).hasClass("slick-resizable-handle")) {
return;
}
var $col = $(e.target).closest(".slick-header-column");
if (!$col.length) {
return;
}
var column = $col.data("column");
if (column.sortable) {
if (!getEditorLock().commitCurrentEdit()) {
return;
}
... While it is probably possible to intercept (and later revert changes in pagination, sorting, filtering etc.) based on the callstack using a custom I know this is a lot to ask for and I'm sure it's just not already baked in by design because of SlickGrid(-universal)'s kind of Frankenstein's heritage (no offense whatsoever, I love it so far 😊). Until we have this feature, I will probably build a temporary solution to disable the relevant UI components while the Thanks for your time, have a nice weekend and stay safe |
Beta Was this translation helpful? Give feedback.
-
I created the lib from scratch over the years, all of it (my own heritage), it's a wrapper on top SlickGrid but most of the code come from Aurelia-Slickgrid/Angular-Slickgrid, I know it's a bit confusing but it's mainly because I had 2 libs already (Angular-Slickgrid, Aurelia-Slickgrid) and I had to create a 3rd grid lib for another project (in Salesforce which uses ES6 syntax), so I made this Slickgrid-Universal as a common lib that could eventually be used by all other libs and I do bug fixes in 1 place instead of replicating in 3 places (now Aurelia-Slickgrid does use Slickgrid-Universal since last Christmas so it's 1 less to maintain for bugs, Aurelia-Slickgrid is down from 11,000 lines of code to just over 1,000 lines of code now because the main code is now coming from Slickgrid-Universal), I know it might confuse people because now I have a wrapper (aurelia-slickgrid/slickgrid-universal) on top of a wrapper (slickgrid) but hey I didn't want to rewrite SlickGrid itself so yeah there's a lot to wrap your head around hehe On adding the The main thing to note is that I use SlickGrid DataView in every cases, even with backend services and in that case I just replace the DataView dataset (with We used the GraphQL Service in my previous project and we did some CRUD, but never really dealt with auto-reverting if something goes wrong, we just display an error and people tend to refresh in general so that was ok (I guess another thing you could do is refresh the grid by calling backend if you encounter an error). When doing edits, if the backend fails, we were just reverting the value in the cell (inline editing) and if it was successful then I always ask for the backend to return the row(s) that was updated (if the backend does any kind of calculations that affects other field then it would be reflected right away because I use the backend response to update the entire row item object), that's usually enough for our usage. I'm totally open for contributions, so if you got something working then please go ahead and create a PR. I can provide guidance for sure. Last question, are you using Slickgrid-Universal directly or you're using it from Aurelia-Slickgrid? I'm just curious, because so far I got no one using Slickgrid-Universal directly (I think), except my team for our Salesforce implementation. |
Beta Was this translation helpful? Give feedback.
-
I think I start to finally understand what you want, it helps to brainstorm in the shower lol.. so if I understand correctly, you want a way to cancel/revert any changes that is page change, edits and whatever else and you want something like calling slickgrid-universal/packages/common/src/services/sort.service.ts Lines 69 to 70 in 20564a3 would require to add an |
Beta Was this translation helpful? Give feedback.
-
Yeah, I know that and I really like your modularization concept and carving out redundant code is always a good idea 👍. But to be honest I wasn't even aware that the original SlickGrid is still used under the hood 😅. I was really surprised, when I saw slick.grid.js and jQuery in debugger a few days ago. I somehow just assumed you had completely rewritten all of SlickGrid given the extreme effort you put in and the huge codebase provided. But of course there is no real point in rewriting all of that and trying to keep up with the fixes and developments over at 6pac/SlickGrid. Hence my Frankenstein's reference, all love.
I use slickgrid-universal, since we already have a frontend framework in use but it lacks components for spreadsheet-like features.
Exactly! I'll have a look to find out where the modifications could be placed and try different solutions. Of course, changes to slickgrid-universal would require those to SlickGrid core to be accepted first, but I guess @6pac would be cool with it. Best regards |
Beta Was this translation helpful? Give feedback.
-
I'm a contributor on the 6pac/SlickGrid because I made lot of changes, fixes, features, plugins, ... and yes the point that there's no need to rewrite something that already exists, so I've pushed lot of fixes on the SlickGrid fork and that benefits both lib and both user base. You should probably start with the if (!options.multiColumnSort) {
var multiSortEventArgs = {
multiColumnSort: false,
columnId: (sortColumns.length > 0 ? column.id : null),
sortCol: (sortColumns.length > 0 ? column : null),
sortAsc: (sortColumns.length > 0 ? sortColumns[0].sortAsc : true)
};
if (trigger(self.onBeforeSorting, multiSortEventArgs) === true) {
trigger(self.onSort, multiSortEventArgs, e);
}
} else {
var singleSortEventArgs = {
multiColumnSort: true,
sortCols: $.map(sortColumns, function(col) {
return {columnId: columns[getColumnIndex(col.columnId)].id, sortCol: columns[getColumnIndex(col.columnId)], sortAsc: col.sortAsc };
})
};
if (trigger(self.onBeforeSorting, multiSortEventArgs) === true) {
trigger(self.onSort, singleSortEventArgs, e);
}
} The only problem I see with that though is that it requires the user to always return or actually wait, we just have to do it exactly like if (!options.multiColumnSort) {
var multiSortEventArgs = {
multiColumnSort: false,
columnId: (sortColumns.length > 0 ? column.id : null),
sortCol: (sortColumns.length > 0 ? column : null),
sortAsc: (sortColumns.length > 0 ? sortColumns[0].sortAsc : true)
};
if (trigger(self.onBeforeSorting, multiSortEventArgs) === false) {
return;
}
trigger(self.onSort, multiSortEventArgs, e);
} else {
var singleSortEventArgs = {
multiColumnSort: true,
sortCols: $.map(sortColumns, function(col) {
return {columnId: columns[getColumnIndex(col.columnId)].id, sortCol: columns[getColumnIndex(col.columnId)], sortAsc: col.sortAsc };
})
};
if (trigger(self.onBeforeSorting, multiSortEventArgs) === false) {
return;
}
trigger(self.onSort, singleSortEventArgs, e);
} or wait again, I was actually going too complicate for no reason, the following would also work since if (trigger(self.onBeforeSorting, multiSortEventArgs) !== false) {
trigger(self.onSort, multiSortEventArgs, e);
} |
Beta Was this translation helpful? Give feedback.
-
Of course I want the changes to be non breaking as optional features should be. |
Beta Was this translation helpful? Give feedback.
-
All good with me. The ony thing I'd say is to mention the tension between say OnUpdate versus BeforeUpdate and AfterUpdate. I prefer the latter because it's more specific. I don't really like OnBeforeUpdate as I think it's unnecessarily mixing the two paradigms. However we have legacy named events to consider, which may restrict the possibilities, unless we deprecate but retain existing events and encourage a second newly named version. |
Beta Was this translation helpful? Give feedback.
-
@6pac you would prefer to see what in the case of Sorting then? I was ok with the |
Beta Was this translation helpful? Give feedback.
-
I'm only referring to the naming. OnSort for example is ambiguous becuase it could be before or after. Frequently there is a multi step process, and the user may need to hook in at various stages. |
Beta Was this translation helpful? Give feedback.
-
@der-david I was waiting for your PR but I guess you worked on something else, anyway the The Filter and Pagination will have to come later, not sure when but eventually will work on them too. EDIT
EDIT 2 a live demo Example 9 is now available or see the animated gif below |
Beta Was this translation helpful? Give feedback.
-
I'm submitting a Feature request
Motivation / Use Case
When using a backend service (e.g. OData) and modified (edited, added, removed) data has not been sent to the server, yet, changes to filters, sorting, pagination and possibly grouping can cause loss of the modified data. I would like to be able to intercept and prevent these option changes to warn the user of the potential loss of unsaved changes.
Expected Behavior
Additional
onBefore...
(abortable) events or optional functions should be available/providable that allow for interception (and abortion) of those option changes.Other Information
I'm willing to help implement these features but I'm open for other ideas, feedback and possible workarounds.
Best regards
David
Beta Was this translation helpful? Give feedback.
All reactions