Rearranging lists in JHipster: What is the best way to do it?

Seeking advice and guidance on implementing a drag-and-drop reorderable list in JHipster 6.7.1.

To illustrate, picture creating a custom ordered list of objects where users can add, remove, and rearrange items. For instance, wanting to move [Epsilon] between [Alpha] and [Beta]:

(before)         (after)
[Alpha]          [Alpha]
[Beta] \---+     [Epsilon]
[Gamma]    |     [Beta]
[Delta]    |     [Gamma]
[Epsilon]--+     [Delta]

Simply drag/drop [Epsilon] between [Alpha] and [Beta], then release to display the updated order. The backend will handle persisting the new ordering while providing an intuitive user experience.

A drag-and-drop reorderable feature enables seamless customization of item ordering. While I have implemented similar functionalities using basic JavaScript libraries, I expected JHipster 6.7.1 to offer a more modern solution.

Ng-bootstrap seems limited to static tools without drag-and-drop capability.

Angular Materials appears promising; however, integrating it with JHipster proved challenging due to conflicts with Bootstrap. Other attempts with SortableJS did not yield success.

In exploring alternative options like PrimeNG, known for its popularity among JHipster developers, I found their Drag/Drop directives useful but lacking examples for simple reorderable lists. Further investigation into PrimeNG's capabilities is ongoing...

While seeking solutions, reaching out to the StackOverflow community for insights:

  • Has anyone successfully implemented a drag-and-drop list reordering system within a JHipster application?
  • What library or method has worked effectively within JHipster - SortableJS/NGX-SortableJS, PrimeNG, or others?
  • Is NG-Dragula a viable option for JHipster applications?
  • Would switching to Vue, React, or another frontend framework provide more flexibility for this functionality?
  • Am I overcomplicating this? Any obvious solutions I might be missing?

Considering different front-end approaches while remaining open to other possibilities during early development stages.

Thank you in advance!

[Development environment: Windows 10 Pro; IntelliJ 2019.3.3; OpenJDK 13; Node 12.15.0; npm 6.13.7; Gradle 6.1.1; Chrome v80.0.3987.116]

[PS: Happy to provide additional details upon request.]

Answer №1

Exploring the capabilities of PrimeNG, I stumbled upon the OrderList feature, which offers a drag-and-drop reordering functionality. While not as sleek as the Angular Material version, it seems to be more elaborate, bordering on overengineering. Simplifying the widget may enhance its usability, but for now, it gets the job done.

A special thanks goes to Jochen Gebsattel for sharing the Jhipster/PrimeNG integration guide. It works like magic.

To implement this in my module, I included the following:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { OrderListModule } from 'primeng/orderlist';

...

@NgModule({
  imports: [..., BrowserAnimationsModule, OrderListModule],
  ...
})
export class ...Module {}

In my component, I made the following additions:

export class ...Component implements OnInit, OnDestroy {
books: string[] = [
                    'Moby Dick',
                    'Brave New World',
                    'Great Expectations',
                    'Wuthering Heights',
                    'King James Bible'
                  ];
lheight: string;

...

  ngOnInit(): void {
    this.lheight = String( 41 * this.books.length ) + 'px';
  }

...

  onReorder(): void {
    console.log(this.books); // eslint-disable-line no-console
  }

}

The component's template was updated as follows:

...

<p-orderList [value]="books" dragdrop="true" (onReorder)="onReorder()" [listStyle]="{'height': lheight}">
  <ng-template let-book pTemplate="item">
    <div class="ui-helper-clearfix">
      <p>{{book}}</p>
    </div>
  </ng-template>
</p-orderList>

...

It's worth noting that the lheight property enables dynamic resizing of the list window to ensure all items are visible at all times.

PrimegNG showcases some appealing features. Though not on par with Angular Material, in the words of my wise grandfather: "If you can't have the one you love, love the one you're with!".

Answer №2

After studying Sudharaka's example project at https://github.com/SudharakaP/JHipsterProtractorDragAndDrop, I successfully integrated @angular/cdk/drag-drop into my Jhipster 6.7.0 project.

Following the jHipster standard generator, I then installed the cdk library using

npm install @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f1f6f9d2aabca0bca1">[email protected]</a>
(note that the version 9.0.1 is not compatible with @angular/core 8.2.14)

To incorporate the DragDropModule in your module:

import { DragDropModule } from '@angular/cdk/drag-drop';
imports: [
  DragDropModule
]

You can then utilize the DragDrop directives as outlined in the official documentation: https://material.angular.io/cdk/drag-drop/overview

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customize the date format of the Datepicker in Angular by implementing a personalized pipe

I am dealing with a datepicker that defaults to the MM/dd/yyyy format, and I need it to adjust based on the user's browser language. For example, if the browser language is English India, then the format should be set to dd/MM/yyyy as shown below. Be ...

Error with Angular InjectionToken utilization

We are encountering an issue while trying to inject a value using InjectionToken. The error message that we are receiving is as follows: ERROR in Error encountered resolving symbol values statically. Only initialized variables and constants ...

Issue with Angular 6: Unable to match nested routes

I am working on a project to test nested routing in Angular. While the app-routes are functioning correctly, I am encountering an error stating that the children "cannot match any routes". After checking other solutions, I am still confused due to version ...

Manipulate inherited CSS styles from an external source

Currently, I am working on creating a pagination using the NG-Bootstrap pagination component. However, I encountered an issue where I need to modify or specifically remove some CSS properties that are applied by default in the NG-Bootstrap library. Is ther ...

"Exploring the interoperability between Angular's ngSanitize and ngDragDrop

Currently, I am facing compatibility issues within my Angular application when trying to incorporate both ngSanitize and ngDragDrop. The ngDragDrop plugin can be accessed at , while ngSanitize documentation is available at https://docs.angularjs.org/api/ng ...

Loading a view in Ionic2 with Angular2 after a successful subscription

After completing an http post request, I want to navigate to the next view in my app. Here is a breakdown of the three services I am using: The server service handles generic http calls such as get and post requests. The city service stores a list of ...

The TypeScript find() method on an array are showing an error message that says, "There is no overload that matches this call

Issue Description I encountered a problem while using TypeScript's find() method for an array. Whenever I input a value, it does not work properly and displays an error message stating, "No overload matches this call". Code Snippet addOption(event: ...

Angular2 - Setting focus on input field during component initialization

Currently, I am working on developing a component in Angular2 (Beta 8) that consists of a textbox and a dropdown. One requirement I have is to automatically set focus on the textbox when the component is loaded or when the dropdown selection changes. Can a ...

The selectors in NgRx store are failing to retrieve data from the main global store

As I delve into the world of ngrx, I find myself struggling to fully understand and implement it effectively within my application. Recently, I integrated ngrx version 8.3 into my project in hopes of organizing my state management efficiently. My goal is ...

Is there a way to set a custom port number for an Angular application?

I am currently in the process of constructing an Angular application. The application is designed to communicate with a server via HttpClient. However, each time the application connects to the server, it utilizes a different port. I am interested in confi ...

Angular Kendo dropdownlist and input textbox are not working together as anticipated

I'm looking to implement a dropdown list similar to Google search using Kendo Angular. However, I've encountered an issue where entering text in the textbox and pressing "Enter" passes the first matching value from the dropdown list to my compone ...

The AgGridModule type does not feature the property 'ɵmod'

Recently, I decided to update my application from Angular 12 to Angular 13. The tools I am using include webpack 5, ag-grid 15.0.0, and ag-grid-angular 15.0.0. While the compilation process goes smoothly for the app, I encountered an issue when trying to l ...

Transform Angular into a library

I've been exploring different options but still haven't nailed down the best approach. I've developed an Angular library with custom components, which I'm converting into Web Components to be used in non-Angular applications. But to mak ...

Headers cannot be modified after they have been sent to the client in Node.js and Angular

I am working on developing login and registration services using Nodejs Express. Every time I make a request in postman, I consistently encounter the same error: https://i.stack.imgur.com/QZTpt.png Interestingly, I receive a response in postman (register ...

415 Media Type Not Supported - Please choose a different format

While working with the backend, I have encountered an issue where the 'DELETE' method is returning a 415 unsupported media type error. After conducting research, it seems that the cause of this error may be due to the content-type header not bein ...

Why isn't the Angular2 ngIf directive updating the DOM?

I am encountering issues with finding the right expression for ngIf to evaluate properly. After following a basic Angularfire2 example, I have successfully managed to log in and out. import { Component } from '@angular/core'; import { AngularFi ...

Unable to update a single object within an array using the spread operator

I am currently working on updating an object within an array and have encountered some issues. In my initial code, I successfully updated a specific property of the object inside the array like this: var equipment = this.equipments.find((e) => e.id === ...

Distinguish among various mat accordion types

I created a custom wrapper for the mat accordion component in Angular Material to handle multiple accordions with different behaviors based on user interaction. Here is my implementation: Wrapper Mat Accordion HTML <mat-accordion> <mat-expa ...

Unlock the Full Potential of TypeScript: Seamless Export of Classes and Functions

In my AngularJS project, I have a separate JavaScript file where I declare prototype functions. Here's an example: function lastConv(){ this.item1="2" this.message="hello" ...... } lastConv.prototype.setupfromThread(data) { this.currentBox = dat ...

Encountering 'npm install' error while trying to follow the Angular2 5 minute

I encountered an error while attempting to follow the Angular2 5 min quick start guide. Can someone assist me in resolving it? vagrant@vagrant-ubuntu-trusty-64:/vagrant/angular2-tutorial$ sudo npm install <a href="/cdn-cgi/l/email-protection" class=" ...