简体   繁体   English

ngx-bootstrap:可与模板排序(水平)

[英]ngx-bootstrap: Sortable with template (horizontally)

I'm currently having an issue using the ngx-bootstrap sortable component.我目前在使用 ngx-bootstrap 可排序组件时遇到问题。

I want to be able to use the sortable component horizontally instead of the stacked vertical examples from the doc examples.我希望能够水平使用 sortable 组件,而不是文档示例中堆叠的垂直示例。 ngx-bootstrap sortable ngx-bootstrap 可排序

Would anyone be able to help out here by providing a potential solution or be able to explain why this may not be possible using ngx-bootstrap.任何人都可以通过提供潜在的解决方案来提供帮助,或者能够解释为什么使用 ngx-bootstrap 可能无法做到这一点。

bs-sortable creates div s internally to show the draggable elements. bs-sortable在内部创建div以显示可拖动元素。 Now by default the display property of div is block , thats why it is arranged in vertical stack.现在默认情况下divdisplay属性是block ,这就是为什么它排列在垂直堆栈中。

To make it horizontal you just need to add the css property display to inline-block in class sortable-item .要使其水平,您只需将 css 属性display添加到 class sortable-item inline-block

Demo演示

Template模板

<div class="row">
  <div class="col">
    <bs-sortable
      [(ngModel)]="itemStringsLeft"
      itemClass="sortable-item"
      itemActiveClass="sortable-item-active"
      placeholderItem="Drag here"
      placeholderClass="placeholderStyle"
      wrapperClass="sortable-wrapper"
    ></bs-sortable>
    <pre class="code-preview">model: {{ itemStringsLeft | json }}</pre>
  </div>
</div>

<div class="row">
  <div class="col">
    <bs-sortable
      [(ngModel)]="itemStringsRight"
      itemClass="sortable-item"
      itemActiveClass="sortable-item-active"
      placeholderItem="Drag here"
      placeholderClass="placeholderStyle"
      wrapperClass="sortable-wrapper"
    ></bs-sortable>
    <pre class="code-preview">model: {{ itemStringsRight | json }}</pre>
  </div>
</div>

styles.css样式文件

.sortable-item {
    padding: 6px 12px;
    margin: 4px;
    font-size: 14px;
    line-height: 1.4em;
    text-align: center;
    cursor: grab;
    border: 1px solid transparent;
    border-radius: 4px;
    border-color: #adadad;
    display: inline-block;
}

EDIT:编辑:

Rather than making changes in global style.css (which will apply changes globally), if you want to make changes in particular component only, you can use ng-deep pseudo selector in particular component.与其在全局style.css进行更改(这将应用全局更改),如果您只想在特定组件中进行更改,则可以在特定组件中使用ng-deep伪选择器。

app.component.css应用组件.css

bs-sortable::ng-deep .sortable-item {
    padding: 6px 12px;
    margin: 4px;
    font-size: 14px;
    line-height: 1.4em;
    text-align: center;
    cursor: grab;
    border: 1px solid transparent;
    border-radius: 4px;
    border-color: #adadad;
    display: inline-block;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM