5

I'm trying to set search disable on specific column. Im using this angular datatable server side.

https://l-lin.github.io/angular-datatables

usually on jquery i can just:

 columns:[{data:"foo", name:"foo", searchable:false}]

I've tried use:

   $scope.dtOptions = DTOptionsBuilder.newOptions()
            .withOption('ajax', {
                url: apiRoot + 'merchant-list'
            })
            .withDataProp('data')
            .withOption('serverSide', true)
            .withOption('order', [0, 'asc'])

  $scope.dtColumns = [
            DTColumnBuilder.newColumn('name', 'Name'),
            DTColumnBuilder.newColumn('type', 'Type'),
            DTColumnBuilder.newColumn('username', 'Username'),
 ]

 $scope.dtColumnDefs = [
            DTColumnDefBuilder.newColumnDef(0),
            DTColumnDefBuilder.newColumnDef(1).withOption('searchable', false),
            DTColumnDefBuilder.newColumnDef(2).withOption('searchable', false)
        ]

seems to work but, the position of columnDef is not correct. when i put newColumnDef(1) searchable to false, the column not to be search should be the second one, but apparently it disable the first column.

Is there way to make it disabled search for specific column and order it?

Thanks

Edit: I've tried 'orderable',false and notvisible is working on columnDef 0. Looks like only searchable is fail.

2 Answers 2

7

Both DTColumnBuilder and DTColumnDefBuilder items must be declared inside an array :

$scope.dtColumns = [
   DTColumnBuilder.newColumn('name', 'Name').withOption('searchable', false)
   ...
]

And then it works -> http://plnkr.co/edit/OOikiBKdLE8R1UEXLyMH?p=preview

or

$scope.dtColumnDefs = [
   DTColumnDefBuilder.newColumnDef('name', 'Name').withOption('searchable', false)
];
Sign up to request clarification or add additional context in comments.

8 Comments

Hi, thanks for answering. notSortable is only for disable sorting. I want disable search for specific column like my above explanation.
@sstarlight, have renewed the answer. I really dont know why I was thinking about sortable and not searchable.
Hi. THanks for reply. looks like i make it worked using columndef but with seperate dtcolumn. sometimes it's not working it still try to find the data. :| looks like i'm going to replace it and use jquery for datatable instead. looks alot easier to handle than angular one. Thanks bro
Hey @sstarlight - I raised it as an issue to the author on github, he responded 15 min later with : "Your $scope.dtColumnDefs must be an array. See the corrected plnkr. (wich is plnkr.co/edit/YIEO1kww7njo5G5I03eV?p=preview) I dont think we come closer to that :) it is ColumnDefs being used in the example.
Hi, thanks for helping me to post it author github. I've updated my answer above. and i stil try to solve it. Looks like the problem is on using server side.
|
7
$scope.dtOptions = {searching:false}

will work fine with latest angular versions.

2 Comments

it works fine but it can replace other property. so better way is to after assign some 'dtOptions' just use $scope.dtOptions.searching = false
Yeah ..! Of course . But if you want set more than one properties. Better approach is to use object notation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.