Giter VIP home page Giter VIP logo

kreuzerk / ng-sortgrid Goto Github PK

View Code? Open in Web Editor NEW
143.0 6.0 19.0 5.77 MB

🧐 A grid that allows you to sort all items via drag & drop. Items can be sorted in all directions (↕️ and ↔️). You can also select and sort multiple items at the same time by pressing ctrl and click on the item.

Home Page: https://kreuzerk.github.io/ng-sortgrid/

License: MIT License

JavaScript 0.47% TypeScript 83.11% HTML 11.81% CSS 4.61%
drag-and-drop sorting multiselect angular hacktoberfest

ng-sortgrid's Introduction

Ng-sortgrid

Travis build badge codecov angular10

Logo

Grid demo

Download

npm i ng-sortgrid

Import the NgsgModule in your AppModule.

  import {NgsgModule} from 'ng-sortgrid'
  ...
  @NgModule({
    imports: [BrowserModule, NgsgModule],
    //...
  })  
  ...

Apply the directive

Loop over your elements with *ngFor. πŸ›ŽοΈ the items needs to be an array. Alternate you can also use the async pipe to pass in your items.

Grid demo

Apply the ngSortgridItem directive

Grid demo

React on changes

In most cases you are interested in the new sort order. Often you want to store them in local storage or even send them to the backend. To do so the following two steps are needed in addition to the "Getting started" step.

Pass your items to the directive via the ngSortGridItems input.

Grid demo React on the 'sorted' output event. The sorted output event emits a NgsgOrderChange which contains the previousOrder and the currentOrder

Grid demo

Group sortgrids

In case you have more than one sortgriditem on the page you need to group the sortgriditems to avoid dropping drags from one group in another group. Pass in a unique name to the ngSortGridGroup input

Grid demo

Use the async pipe

You can also use the async pipe to display items

Grid demo

Style your items on different events

The ng-sortgrid adds different classes on different events to your items. You can either use those classes to style the appereance of your items on certain events or you can include the build in CSS from the ng-sortgrid library.

Integrate the build in CSS

To integrate the built in Stylesheet just import in in your angular.json.

    "styles": [
              "node_modules/ng-sortgrid/styles/ngsg.css",
            ],

Alternative you can provide custom styles for the different classes listed bellow

Class Description
ng-sg-placeholder This class is added to the placeholder item which previews where the item is inserted
ng-sg-dropped This class is added as soon after you drop an item. The class will be on the item for 500 milliseconds before it gets removed
ng-sg-selected This class is added when you press the CMD or the Ctrl Key and Click on an item. It indicates which items are selected for the multi drag&drop
ng-sg-active This class is added when dragging item

Scrolling

The ng-sortgrid has a autoScroll flag which you can use to enable autoScroll. If you enable autoScroll the screen will start to scroll in the following scenario.

Grid demo

  • If you drag an element in the top 50px of the screen
  • If you drag an element in the bottom 50px of the screen

Custom scroll points

Sometimes its not enough to only scroll once you drag over the top view port border. Imagine that you have a fixed navbar at the top of your page. In this case you need to scroll once you drag an element over the navbar.

Scroll speed (default 50)

The scrollSpeed property accepts a number and allows you to specify the scrolling speed.

Check out the scroll demo

API

Inputs

Value Description Default
ngSortGridGroup: string Groups a grid - avoids that items from one grid can be dragged to another grid undefined
ngSortGridItems: any[] Sort grid items. Pass down a list of all your items. This list is needed to enable the sorting feature. undefined
autoScroll: boolean Flag to enable autoscrolling false
scrollPointTop: number Custom top scrollpoint in pixels if autoscroll is applied we start scrolling if we pass the top border
scrollPointBottom: number Custom bottom scrollpoint in pixels if autoscroll is applied we start scrolling if we pass the bottom border
scrollSpeed: number Scrollspeed, the higher the value, the higher we scroll. 50 - only applies if autoscrolling is on

Outputs

Value Description Default
sorted: EventEmitter<NgsgOrderChange Emits an event after we sorted the items, each event is of type NgsgOrderChange. The NgsgOrderChange contains the previousOrder and the currentOrder. Both are freshly created arrays. undefined

Mobile usage

If you want to use those events on mobile you probably have to use some polyfills in order to emit all the needed events. Including this polyfill in your app should do the trick. https://github.com/timruffles/mobile-drag-drop.

ng-sortgrid's People

Contributors

dependabot[bot] avatar kreuzerk avatar manuel-ego avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ng-sortgrid's Issues

working with shift-selection problems

For this we assume the following layout:

1 2 3 4  5
6 7 8 9 10
  1. single item is not always selected (bug)

steps2repoduce: normal click on [1] > then shift click on [1] > [1] is not selected
fix: [1] should be selected

  1. SOME NAME FOR THIS POINT (bug)

steps2repoduce: shift click [1] + [2] > normal click [3] and drag > [1] + [2] is dragged
fix: [1] + [2] should be deselected and [3] should be dragged

  1. remove the selection (feature)

steps2repoduce: shift click [1] + [2] > normal click somewhere on the drag grid > nothing happens
fix: [1] + [2] should be deselected

  1. moving horizontal selection to edge (bug)

steps2repoduce: shift click [1] + [2] > drag over 5 > results in unexpected order
fix: i expect:

3 4 5 1  2
6 7 8 9 10
  1. moving vertical selection

steps2repoduce: shift click [1] + [6] > drag over 5 > results in unexpected order
fix: i expect: (not entirely sure)

2 3 4  5 1
7 8 9 10 6

NPM peerDependencies warnings

I've just updated to version 4.0.0 of ng-sortgrid.
Unfortunately the following warnings of NPM haven't dissappeared yet:

npm WARN [email protected] requires a peer of @angular/common@^7.2.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^7.2.0 but none is installed. You must install peer dependencies yourself.

I'm using the newest version of Angular, version 10.0.14.
"@angular/core": "10.0.14"
"@angular/common": "10.0.14"

Please update your peerDependencies in your package.json.

Best regards,
Andy

feature: add 2 new inputs: disableSorting and disableMultipleSorting

Need implement 2 new inputs like this.

<div class="example-container">
  <div *ngFor="let item of items"
       ngSortgridItem
       [disableSorting]="false"
       [disableMultipleSorting]="true"
       [ngSortGridItems]="items"
       (sorted)="logger($event)"
  >
    <div class="example-box">{{item}}</div>
  </div>
</div>

Problem with nested lists

Currently, I am using this library to sort a list and everything works fine. Now we want to have a nested list and sort every list independent of each other. For that I thought that I only have to use the directives in the sublist but give it another group name. But unfortunately that doesn't work as expected. I've attached a video that shows the behavior.

Am I doing something wrong or is this not supported yet?

Bildschirmaufnahme.2023-10-20.um.12.32.55.mov

Change type of a placeholder element

Hello!
In my project it's need to change element's type when drag element changes its position.
For example, first three elements should be like ElemA, and other should be like ElemB. These are different components.
In static everything is OK, but when I'm dragging element a placeholder element appears, and it don't changes because it's copy of dragged element.

Q: How to change the placeholder element's type?
image
image

Can't apply the directive

It fails at this step

  import {NgsgModule} from 'ng-sortgrid'
  ...
  @NgModule({
    imports: [BrowserModule, NgsgModule],
    //...
  })  
  ...

Cannot find module 'ng-sortgrid' or its corresponding type declarations

Value at position 1 in the NgModule.imports of AppModule is not a reference
Value could not be determined statically

I'm using Angular 14

Not compatible with lazy loaded projects

Hey there :-)

I just tried your sort-grid. Sadly, it does not even compile when not using in the root app module. And when using in the root module and then trying to add functionality to a submodule, it does not find the service anymore.

I guess you just need to provide the service in the NgsgModule instead of root ?

Then it would be correctly scoped.

LG

6.0.0 still depends on Angular 12

Hi,

Thanks for the Angular 13 Update. But it still show up errors because the dependencies still using Angular 12

Any fixes coming up ?

Update docs

Mention in the docs that the values you get on the sorted output are not the original objects.

hi, i meet this error

CommonDemoComponent.html:16 ERROR NullInjectorError: StaticInjectorError(AppModule)[NgsgItemDirective -> NgsgSortService]:
StaticInjectorError(Platform: core)[NgsgItemDirective -> NgsgSortService]:
NullInjectorError: No provider for NgsgSortService!

Please, add new event

Please, add event for dropping drags from one sortgriditem in another sortgriditem.

ng-sortgrid doesn't work in lazy loaded modules

Hi Kevin,

Thanks a lot for creating ng-sortgrid !

ng-sortgrid works perfectly fine in app.component.html or when used in a component without lazy loading.

While Using ng-sortgrid in lazy loaded module. I am getting the following error-

Can't bind to 'item' since it isn't a known property of 'ngsg-card'.

  1. If 'ngsg-card' is an Angular component and it has 'item' input, then verify that it is part of this module.
  2. If 'ngsg-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

is it possible to use ng-sortgrid in lazy loaded modules?

"@angular/cli": "~8.3.17"
"ng-sortgrid": "1.3.3"

Best Regards
Nik

How to use on mobile ?

Hi,

I was wondering if it was useable on mobile ? It seems to me that touch events are not working.

Thank you

Missing CSS file

"node_modules/ng-sortgrid/dist/lib/ngsg.css"

The file is not included in the npm package
"ng-sortgrid": "^3.0.1",

image

Version 5 peer dependencies for Angular 10 instead of 12

You wrote in your release that version 5 is adjusted for Angular 12, but in your library's package.json there are still the peer dependencies for Angular 10.

"peerDependencies": {
    "@angular/common": "^10.0.0",
    "@angular/core": "^10.0.0"
  }

Shouldn't it be

"peerDependencies": {
    "@angular/common": "^12.0.0",
    "@angular/core": "^12.0.0"
  }

?

No provider for NgsgSortService

Hi. I think that it is the same issues as #30 but it is already closed. When I use ng-sortgrid from demo folder from github not from npm or yarn - it works well

NullInjectorError: StaticInjectorError(AppModule)[NgsgItemDirective -> NgsgSortService]: StaticInjectorError(Platform: core)[NgsgItemDirective -> NgsgSortService]: NullInjectorError: No provider for NgsgSortService! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (http://localhost:4200/vendor.js:76429:25) at resolveToken (http://localhost:4200/vendor.js:87622:24) at tryResolveToken (http://localhost:4200/vendor.js:87566:16) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http://localhost:4200/vendor.js:87468:20) at resolveToken (http://localhost:4200/vendor.js:87622:24) at tryResolveToken (http://localhost:4200/vendor.js:87566:16) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http://localhost:4200/vendor.js:87468:20) at resolveNgModuleDep (http://localhost:4200/vendor.js:95938:29) at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (http://localhost:4200/vendor.js:96609:16) at resolveNgModuleDep (http://localhost:4200/vendor.js:95938:29)

duplicate selected col while draging

When I select multi-columns and drag, columns are duplicate
basically some dealy issue in plugin when we drag and during this if some dealy plugin move product but we still drag so it make copy

Scrolling not working on multiple item drag and drop for sorting on Windows

Hi,

I am using this package for my site, in-order to sort items by drag and drop. When I select multiple items and drag for sorting, browsers like firefox, edge, chrome in windows machines are not auto-scrolling on moving the dragged items to top or bottom as like in the browsers used in linux/mac machines.

I also checked your demo(scrolling) on windows browsers where I experienced the same.

Angular 16 support

Hey,
first of all thank you a lot for creating and maintaining this project. You helped my project a lot over the last year.

Do you plan to update the package to Angular 16 and if so do you have an eta for the release?

Thanks a lot.

Card item select and drag on scrolling mouse wheel in Windows OS browsers

Hi Support,

I have used your sortgrid package in my application, in which I listed products on Card grid. On selecting the product card and dragging, it autoscroll by default. My issue is in windows os browsers(edge, chrome, firefox), on selecting the product card on mouse left click and when scrolling the mouse wheel, card is not dragging. But the same scenario is working well in MAC OS browsers.

I tried your demo version in Windows OS browsers too, it didn't work as my need. Is there any fix for this issue?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing package.json file.

A package.json file at the root of your project is required to release on npm.

Please follow the npm guideline to create a valid package.json file.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Angular 15 compatibility

Hi,

First of all, thanks for your package !

Do you prepare an Angular 15 compliant version ?

Thanks :)

[RFC] Sorted output interface

It would be pretty nice to have a public (exported by the library) interface for sorted output that will contain not only a sorted list but previous and current indexes.

And thanks for the great library!

Angular 17

Hi! Thanks a lot for your great lib! Do you have any plans to update it for Angular v17?

ng-sg-active not implemented

And as far as I could see in the source code .ng-sg-active is not implemented anymore? Should be possible to style the dragged element

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.