handsontable / handsontable

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡
https://handsontable.com
Other
19.26k stars 2.96k forks source link

Ignore first rows while filtering and sorting #3672

Closed helmutgranda closed 7 years ago

helmutgranda commented 7 years ago

I have a custom dropdown for filtering, also need the ability to sort the data. Currently I am not able to do so since filtering and sorting applies to all the data including for headers. How can I implement a similar behavior while Ignoring the first row after header?

In the following example the first row has values of "Do not sort" which would be great to ignore for sorting and filtering.

http://jsfiddle.net/9rofomd5/

AMBudnik commented 7 years ago

Hi @helmutgranda Unfortunately this option is not available at the moment. We have also two related bugs (sorting a summaryCalculations row and the fixed rows). I'll mark your idea as a feature.

helmutgranda commented 7 years ago

Hi @AMBudnik,

Thanks for adding this as a feature, one thing that I have done is adding my sorting dropdown inside the header area which works great, however it looks like the header area goes through the sorting and filter algorithms as well. Is there a way to ignore the header tags from the table and leave them intact during those two behaviors?

AMBudnik commented 7 years ago

Could you share a Fiddle with updated code? I'd be happy to take a look at it.

helmutgranda commented 7 years ago

Hi @AMBudnik,

Sure, I have created a demo for you:

http://jsfiddle.net/helmutgranda/sLyt95kh/1/

One thing that you will notice is that I am updating the data of the headers without HandsonTable API but rather updating from outside. Long story short we have dropdowns in headers that filter the data on the table similar to what comes out of the box but with some modifications. However when you interact with the dropdowns the filtering happens and the data in our dropdown headers get updated. The easiest way to see this in action is as follows:

  1. Load the page
  2. Click on "Update Header" div above the table
  3. Notice all headers change to the string "Cars"
  4. Click on any of the "Cars" headers for sorting
  5. Headers get reversed to original state loosing the "Cars" update
AMBudnik commented 7 years ago

Hi @helmutgranda I can see what you mean and the table is over-witting your new headers. Is there any particular reason why not to use updateSettings with colHeaders to change them?

AMBudnik commented 7 years ago

Hi again @helmutgranda I just got a demo from our devs where you can ignore first row while sorting: http://jsfiddle.net/budnix/8n9cdnc8/

helmutgranda commented 7 years ago

Hi @AMBudnik,

Thanks for the response and in fact the first row is ignored, however since we are updating the data of the cell outside the table it gets overwritten with what is in memory. I am able to get around this limitation by listen to specific events.

AMBudnik commented 7 years ago

great, thanks for keeping me updated.

AMBudnik commented 7 years ago

We're moving this topic to our Feature-requests section

zachary822 commented 7 years ago

Would it be possible for @AMBudnik to share the ignore first row demo code again? The url is no longer working.

AMBudnik commented 7 years ago

Sure @zachary822 Here it is: http://jsfiddle.net/handsoncode/y2ttkwt6/ in this example we ignore 2 rows a[0] === 0 || a[0] === 1

zachary822 commented 7 years ago

Thank you!

AMBudnik commented 7 years ago

@zachary822 you're welcome :)

mohithg commented 6 years ago

Is there a way to ignore last row instead of first row?

AMBudnik commented 6 years ago

@mohithg

unfortunately, this option works only for first adjacent rows.

mohithg commented 6 years ago

@AMBudnik I did the following to make it work. return function (a, b) { const plugin = hot.getPlugin('columnSorting'); if (b[0] === (hot.countRows() - 1)) { return -1; } return plugin.defaultSort(sortOrder, columnMeta)(a, b); };

AMBudnik commented 6 years ago

you're right @mohithg such a clever solution. Thanks for sharing!

zawmyohtet1 commented 5 years ago

Hi @AMBudnik , Is there any sample codes for v7.0.2? :)

AMBudnik commented 5 years ago

Hey @zawmyohtet1 the last demo should work for all the versions below 6.0.0. In 6.0.0. we've made some breaking changes https://handsontable.com/docs/6.0.0/tutorial-release-notes.html and haven't created the demo since then.

However, we should think of an option that will allow us to exclude some rows from being sorted, like excludeFromSorting: [0,1] where 0 and 1 are indexes of visible rows. We could also add a boolean option dontSortFixedRows then we just could fix the rows and keep them unsortable.

zawmyohtet1 commented 5 years ago

Thank you :)

aljke commented 4 years ago

Hi Are there any samples for ignoring the first row while filtering?

AMBudnik commented 4 years ago

Hi @aljke thee are no update since my comment in April

galvakojis commented 4 years ago

maybe some future plans? cause year already passed

AMBudnik commented 4 years ago

Hey @galvakojis We are working on the v8 of Handsontable, where (as we believe) it will be possible to exclude rows from being sorted. Here's an example based on 8.0.0.-beta1 https://jsfiddle.net/wojciech/2rdua5ek I haven't tested filtering but I stay positive.

wojciechczerniak commented 4 years ago

I haven't tested filtering but I stay positive.

You're example includes fixed rows with filters as well.

AMBudnik commented 4 years ago

@wojciechczerniak true, I should have explained it better - values from the first two rows cannot be filtered out but they're visible in the filter_by_value list so I consider filtering partially supported for excluding rows.

galvakojis commented 4 years ago

@AMBudnik thank you looks like it is working, kind of, cause I am using angular now I have bunch of errors: Still this works in development, but not sure will it work in prod

    ERROR in node_modules/@handsontable/angular/lib/hot-table.component.d.ts:276:42 - error TS2339: Property 'modifyCol' does not exist on type 'GridSettings'.

    276     modifyCol: Handsontable.GridSettings['modifyCol'];
                                                 ~~~~~~~~~~~
    node_modules/@handsontable/angular/lib/hot-table.component.d.ts:283:42 - error TS2339: Property 'modifyRow' does not exist on type 'GridSettings'.

    283     modifyRow: Handsontable.GridSettings['modifyRow'];
                                                 ~~~~~~~~~~~
    node_modules/@handsontable/angular/lib/hot-table.component.d.ts:293:48 - error TS2339: Property 'skipLengthCache' does not exist on type 'GridSettings'.

    293     skipLengthCache: Handsontable.GridSettings['skipLengthCache'];
                                                       ~~~~~~~~~~~~~~~~~
    node_modules/@handsontable/angular/lib/hot-table.component.d.ts:294:44 - error TS2339: Property 'unmodifyCol' does not exist on type 'GridSettings'.

    294     unmodifyCol: Handsontable.GridSettings['unmodifyCol'];
                                                   ~~~~~~~~~~~~~
    node_modules/@handsontable/angular/lib/hot-table.component.d.ts:295:44 - error TS2339: Property 'unmodifyRow' does not exist on type 'GridSettings'.

    295     unmodifyRow: Handsontable.GridSettings['unmodifyRow'];
                                                   ~~~~~~~~~~~~~
AMBudnik commented 4 years ago

@galvakojis that's a beta version - we will make an update for Angular, React, and Vue after publishing a stable version. Some of the hooks will be deprecated in 8.0.0 https://github.com/handsontable/handsontable/pull/6613

galvakojis commented 4 years ago

@AMBudnik understood, maybe there is something like a road map? When you are expecting to release v8? Q2? Q3? Q4? Next year?

AMBudnik commented 4 years ago

@galvakojis here' an epic to follow https://github.com/handsontable/handsontable/issues/6465 However, we do not have to fix all those issues to publish beta2. Stable 8 version needs to have all the regressions fixed so that would take us another 2-3 weeks. I hope that we will be able to push beta2 in May but I cannot guarantee the date.

AMBudnik commented 2 years ago

Hi All.

We are moving feature ideas and improvements to Github Discussions to gather all the ideas on UI and API. That will help us to continue the development of the functionality in the future.

Please feel welcome to share your feedback via the Github Discussions panel if you have any additional ideas.