GithubHelp home page GithubHelp logo

manishjanky / ngx-sortable Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 15.0 4.72 MB

ngx-sortable is an angular sortable list components that support drag and drop sorting

License: MIT License

JavaScript 8.46% TypeScript 50.45% HTML 29.30% SCSS 8.57% CSS 3.22%
sortable-lists sortable sorting angualar4 angular angular-components component library ngx-sortable drag-and-drop

ngx-sortable's Introduction

ngx-sortable

GitHub license npm Codecov branch npm GitHub top language GitHub code size in bytes GitHub issues GitHub closed issues GitHub contributors

ngx-sortable an angular 4 and above component for sorting list supporting drag and drop sort.

Features

  • Custom template
  • Customizable
  • Drag and drop sorting
  • Use keyboard to sort
  • Remove elements

Examples

Installation

  • npm install ngx-sortable

Using with webpack and tsc builds/ angular-cli builds

  • import NgxSortableModule into your app.module;
import { NgxSortableModule } from 'ngx-sortable'
  • add NgxSortableModule to the imports of your NgModule:
@NgModule({
  imports: [
    ...,
    NgxSortableModule
  ],
  ...
})
class YourModule { ... }
  • use <ngx-sortable></ngx-sortable> in your templates to add sortable list in your view

Deprecated

    <ngx-sortable [items]="items" [name]="'List'" (listSorted)="listOrderChanged($event)">
        <ng-template let-item>
            <div class="sortable-list-item">
                {{item}}
            </div>
        </ng-template>
    </ngx-sortable>

v2.0.0 onwards use below

    <ngx-sortable [items]="items" [name]="'List'" (listSorted)="listOrderChanged($event)">
        <ng-template let-item="item">
            <div class="sortable-list-item">
                {{item}}
            </div>
        </ng-template>
    </ngx-sortable>

Where content inside <ng-template> </ng-template> is the template that will be used for displaying list items. Also the class can be named accordingly this is just an example. Create a class and add it to your root style.css

Notice the difference in accessing the item in above two examples. Also from v2.0.0 onwards index of the item is also available in the template similar to let-item="item" use let-i="index" and i will be the index variable available in the template.

Config

Input

  • items: any[] - array of list items.
  • name: string - List name that will be shown in the header.
  • listStyle: any - list styles such as height, width.
  • showHeader: boolean - flag to hide / show header default is true
  • removeOnDropOutside: boolean - flag to enable remove items by dragging and dropping them outside the list. Default is false
  • arrowKeySort: boolean - flag to enable sort using keyboard arrow keys. Example: Ctrl + ArrowDown moves item down
  • commandKey: CommandKey - key type to use along with arrow keys for sorting e.g. ctrlKey/altKey. Default is ctrlKey
enum CommandKey {
  CtrlKey = "ctrlKey",
  ShiftKey = "shiftKey",
  Altkey = "altKey",
  MetaKey = "metaKey",
}
listStyle = {
        width:'300px', //width of the list defaults to 300
        height: '250px', //height of the list defaults to 250
      }

Output

  • listSorted($event): Event - when list is sorted emits listSorted event with updated order

Where $event is the sorted list

  • dragStart($event): Event - emitted when an item is seleceted and starts dragging

Where $event:{ event: Javascript event, itemIndex: current item index, newIndex: -1, item: selected item}

  • dropped($event): Event - emitted when an item is dropped at the new index

Where $event:{ event: Javascript event, itemIndex: current item index, newIndex: new item index, item: selected item}

  • moveDown($event): Event - emitted when an item is moved down in the list using the sort arrows

Where $event:{ itemIndex: current item index, newIndex: new item index, item: selected item}

  • moveUp($event): Event - emitted when an item is moved up in the list using sort arrows

Where $event:{ itemIndex: current item index, newIndex: new item index, item: selected item}

  • remove($event): Event - emitted when an item is removed from the list by dropping out, only works when removeOnDropOutside is set to true

Where $event:{ itemIndex: current item index, item: selected item}

Help Improve

Found a bug or an issue with this? Open a new issue here on GitHub.

Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.

ngx-sortable's People

Contributors

dependabot[bot] avatar manishjanky avatar

Stargazers

 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

ngx-sortable's Issues

Auto adjust the empty space of the item using sortable

Used Sortablejs in one of the module, where i have provided the functionality of Manage widget, functionality wise, while i am dragging the list item from the manage widget, the associated widget should get change the position.
ss3

Issue : In the module, i have two size of widgets (small and large), While placing small widget next to large one, it is taking by default height and cause white space.
ss4

Expectation : Small widgets which is next to large, it should get auto adjust the empty space and other small widget should get placed up in the empty space.
SS1

Refer screenshots : SS

Support for nested list with same items structure

Do you intend to Support for nested list with same items structure like the object below?

filteredObject: any[] = [
    { type: 'link', data: { label: 'Link 1', link: 'http://localhost:9000/' } },
    {
      type: 'group', data: {
        label: 'Group 1', children: [
          { label: 'Link 3', link: 'http://localhost:9000/' },
          { label: 'Link 4', link: '#' }
        ]
      }
    },
    { type: 'link', data: { label: 'Link 1', link: '#' } }
  ];

Angular 10.0.11 build issues.

Bug description

Upgrading from 1.0.3 -> 2.1.0, Fails to build

Expected result

Successful build.

Actual result

ERROR in node_modules/ngx-sortable/lib/components/ngx-sortable/ngx-sortable.component.d.ts:31:21 - error TS2694: Namespace '"C:/Users/****/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.

31     static ɵfac: i0.ɵɵFactoryDeclaration<NgxSortableComponent, never>;
                       ~~~~~~~~~~~~~~~~~~~~
node_modules/ngx-sortable/lib/components/ngx-sortable/ngx-sortable.component.d.ts:32:21 - error TS2694: Namespace '"C:/Users/****/node_modules/@angular/core/core"' has no exported member 'ɵɵComponentDeclaration'.

32     static ɵcmp: i0.ɵɵComponentDeclaration<NgxSortableComponent, "ngx-sortable", never, { "items": "items"; "name": "name"; "showHeader": "showHeader"; "removeOnDropOutside": "removeOnDropOutside"; "listStyle": "listStyle"; }, { "dragStart": "dragStart"; "dropped": "dropped"; "moveDown": "moveDown"; "moveUp": "moveUp"; "remove": "remove"; "listSorted": "listSorted"; }, ["itemTemplate"], never, false>;
                       ~~~~~~~~~~~~~~~~~~~~~~
node_modules/ngx-sortable/lib/ngx-sortable.module.d.ts:5:21 - error TS2694: Namespace '"C:/Users/****/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.

5     static ɵfac: i0.ɵɵFactoryDeclaration<NgxSortableModule, never>;
                      ~~~~~~~~~~~~~~~~~~~~
node_modules/ngx-sortable/lib/ngx-sortable.module.d.ts:6:21 - error TS2694: Namespace '"C:/Users/****/node_modules/@angular/core/core"' has no exported member 'ɵɵNgModuleDeclaration'.

6     static ɵmod: i0.ɵɵNgModuleDeclaration<NgxSortableModule, [typeof i1.NgxSortableComponent], [typeof i2.CommonModule], [typeof i1.NgxSortableComponent]>;
                      ~~~~~~~~~~~~~~~~~~~~~
node_modules/ngx-sortable/lib/ngx-sortable.module.d.ts:7:21 - error TS2694: Namespace '"C:/Users/****/node_modules/@angular/core/core"' has no exported member 'ɵɵInjectorDeclaration'.

7     static ɵinj: i0.ɵɵInjectorDeclaration<NgxSortableModule>;
                      ~~~~~~~~~~~~~~~~~~~~~

Steps to reproduce

N/A

Context

Your Environment

  • Version used: 2.0.0 or 2.1.0 . "@angular/core": "^10.0.11",
  • Browser Name and version: N/A
  • Operating System and version: Windows 11
  • Link to your project: N/A

Drop out of drop zone

when an item dropped out of the zone selected drop zone to stay selected but better then it will remove and drag will cancel

Item can be dragged under itself, and after dropping will appear after the next item, instead of before it.

This bug is reproducible in the demo.

  1. pick up the third item ("Amie Franklin") in the list
  2. at first the drop target will be above "Amie Franklin" in the list
  3. drag the floating placeholder down just a little until it is under "Amie Franklin", but above the fourth item
  4. drop the floating placeholder
  5. the list will resort and "Amie Franklin" will appear in the fourth position, and the item which was below the drop target will be third

Expected behaviour:

  • when a list item is dropped above or below itself, it should remain at the same position

error NG6002

1 When I add this package to my sharedModules file I get this error

 ERROR in node_modules/ngx-sortable/dist/ngx-sortable.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of SharedModule, but could not be resolved to an NgModule class.

    This likely means that the library (ngx-sortable) which declares NgxSortableModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

2 Also I want to know is it possible I use my own design instead of default list design?

Something like this:

Screenshot(5)

Unable to hide header and other stylings

Hi Manish, I am unable to hide header and other ui components. Kindly, guide me to hide it and please provide a complete documentation so that I can understand about each and every element variables.

A compatible version with Angular 15

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

A clear and concise description of what you want to happen.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Corrección en el código

Al insertar un texto a la lista me colocar el primer index en undefined ajustar código para evitar este error.

NgxSortableComponent.prototype.handleDrop = function (droppedIndex) {

    var item = this.items[this.draggedIndex];
    if (item === undefined) { return false;} // "see" codigo temporal evita ordenar lista con  undefined -1
    this.items.splice(this.draggedIndex, 1);
    this.items.splice(droppedIndex, 0, item);
    this.draggedIndex = -1;
    this.onDragOverIndex = -1;
    this.listSorted.emit(this.items);
};

Cannot read property 'id' of undefined

I just installed the plugin and added in app.module.ts and nothing else. I am getting this error Cannot read property 'id' of undefined at registerNgModuleType (core.js:35936)

Screenshot 2020-10-13 at 12 31 58 PM

Versions are as below

"ngx-sortable": "^1.0.3",

"@angular/animations": "^9.0.6",
"@angular/cdk": "^9.1.3",
"@angular/common": "^9.0.6",
"@angular/compiler": "^9.0.6",
"@angular/core": "^9.0.6",
"@angular/forms": "^9.0.6",
"@angular/http": "^7.2.16",
"@angular/platform-browser": "^9.0.6",
"@angular/platform-browser-dynamic": "^9.0.6",
"@angular/router": "^9.0.6",

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.