0

i am creating some tables using ngx-datatable tool in angular 4. i need one column ie. first column of that table must not be reorderable and all other columns must be orderable. can anybody help me out?

uma mahesh
  • 61
  • 7

1 Answers1

1

You will need to make use of the draggable input property binding.

I believe on your component.html, your ngx-datatable component looks something like this. For the first ngx-datatable-column you will need to set the draggable property of the first column as false. As for the other columns, you can set draggable as true, though draggable is true by default, hence there is actually no need to specify it.

<ngx-datatable #table class="bootstrap" [columns]="dataColumns">
  <!-- First column is not draggable -->
  <ngx-datatable-column [width]="30" [draggable]="false">
                            ...
  </ngx-datatable-column>
  <!-- The other columns are draggable -->
  <ngx-datatable-column *ngFor="let column of dataColumns| slice:1; let i = index;" name="{{column.name}}" prop="{{column.prop}}" [draggable]="true">
  ...
  </ngx-datatable-column>
</ngx-datatable>

And on your component.ts, you will need to define your dataColumns.

dataColumns = [
    {
      prop: 'id',
      name: 'ID'
    },
    .
    .
    // other column definitions

]
wentjun
  • 40,384
  • 10
  • 95
  • 107
  • Thankyou for your answer. we have already tried this. but the problem is , whenever we drag any other column on to first column, the first column is automatically swapped with other column's position – uma mahesh Apr 01 '19 at 06:12
  • Oh my.. I just discovered this issue too. I don't think I have a solution for that. Maybe you should post this on their github page instead? Create an issue, or feature-request? – wentjun Apr 01 '19 at 07:01