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.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
ssuhat
  • 7,387
  • 18
  • 61
  • 116

2 Answers2

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)
];
davidkonrad
  • 83,997
  • 17
  • 205
  • 265
  • 1
    Hi, thanks for answering. notSortable is only for disable sorting. I want disable search for specific column like my above explanation. – ssuhat Sep 23 '15 at 11:51
  • @sstarlight, have renewed the answer. I really dont know why I was thinking about sortable and not searchable. – davidkonrad Sep 23 '15 at 12:41
  • 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 – ssuhat Sep 25 '15 at 09:34
  • 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 http://plnkr.co/edit/YIEO1kww7njo5G5I03eV?p=preview) I dont think we come closer to that :) it is ColumnDefs being used in the example. – davidkonrad Sep 25 '15 at 10:04
  • 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. – ssuhat Sep 25 '15 at 10:09
  • I've tried 'orderable',false and notvisible is working on columnDef 0. Looks like only searchable is fail. – ssuhat Sep 25 '15 at 11:15
  • I am sure you are doing it in the wrong order. The whole idea with columnDefs is that you not have to declare all the columns over and over. – davidkonrad Sep 25 '15 at 11:44
  • Hi, yes. but as i know columndefs will read the target even i declare all of it – ssuhat Sep 25 '15 at 11:45
7
$scope.dtOptions = {searching:false}

will work fine with latest angular versions.

slfan
  • 8,950
  • 115
  • 65
  • 78
learn2code
  • 153
  • 2
  • 8
  • 1
    it works fine but it can replace other property. so better way is to after assign some 'dtOptions' just use $scope.dtOptions.searching = false – Shivam Mishra Jun 22 '17 at 04:41
  • Yeah ..! Of course . But if you want set more than one properties. Better approach is to use object notation. – learn2code Sep 15 '17 at 08:23