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?
Asked
Active
Viewed 1,076 times
0
-
Do you mean you do not want your first column to be 'sortable'? E.g. no sorting of the first column when you click the header? – wentjun Apr 01 '19 at 05:14
-
no. i mean first column must not be swappable with any other column. the position or order of the first column must not be changed. – uma mahesh Apr 01 '19 at 05:30
-
Alright , i have updated my answer. – wentjun Apr 01 '19 at 05:50
1 Answers
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