@@ -104,10 +104,10 @@ abstract class DataTableAbstract implements DataTable
104104 * @var array
105105 */
106106 protected array $ templates = [
107- 'DT_RowId ' => '' ,
107+ 'DT_RowId ' => '' ,
108108 'DT_RowClass ' => '' ,
109- 'DT_RowData ' => [],
110- 'DT_RowAttr ' => [],
109+ 'DT_RowData ' => [],
110+ 'DT_RowAttr ' => [],
111111 ];
112112
113113 /**
@@ -148,6 +148,8 @@ abstract class DataTableAbstract implements DataTable
148148
149149 protected mixed $ transformer ;
150150
151+ protected bool $ editOnlySelectedColumns = false ;
152+
151153 /**
152154 * Can the DataTable engine be created with these parameters.
153155 *
@@ -245,7 +247,13 @@ public function ignoreGetters(): static
245247 */
246248 public function editColumn ($ name , $ content ): static
247249 {
248- $ this ->columnDef ['edit ' ][] = ['name ' => $ name , 'content ' => $ content ];
250+ if ($ this ->editOnlySelectedColumns ) {
251+ if (! count ($ this ->request ->columns ()) || in_array ($ name , Arr::pluck ($ this ->request ->columns (), 'name ' ))) {
252+ $ this ->columnDef ['edit ' ][] = ['name ' => $ name , 'content ' => $ content ];
253+ }
254+ } else {
255+ $ this ->columnDef ['edit ' ][] = ['name ' => $ name , 'content ' => $ content ];
256+ }
249257
250258 return $ this ;
251259 }
@@ -598,6 +606,18 @@ public function skipPaging(): static
598606 return $ this ;
599607 }
600608
609+ /**
610+ * Skip auto filtering as needed.
611+ *
612+ * @return $this
613+ */
614+ public function skipAutoFilter (): static
615+ {
616+ $ this ->autoFilter = false ;
617+
618+ return $ this ;
619+ }
620+
601621 /**
602622 * Push a new column name to blacklist.
603623 *
@@ -881,10 +901,10 @@ protected function processResults($results, $object = false): array
881901 protected function render (array $ data ): JsonResponse
882902 {
883903 $ output = $ this ->attachAppends ([
884- 'draw ' => $ this ->request ->draw (),
885- 'recordsTotal ' => $ this ->totalRecords ,
904+ 'draw ' => $ this ->request ->draw (),
905+ 'recordsTotal ' => $ this ->totalRecords ,
886906 'recordsFiltered ' => $ this ->filteredRecords ?? 0 ,
887- 'data ' => $ data ,
907+ 'data ' => $ data ,
888908 ]);
889909
890910 if ($ this ->config ->isDebugging ()) {
@@ -948,11 +968,11 @@ protected function errorResponse(\Exception $exception)
948968 $ this ->getLogger ()->error ($ exception );
949969
950970 return new JsonResponse ([
951- 'draw ' => $ this ->request ->draw (),
952- 'recordsTotal ' => $ this ->totalRecords ,
971+ 'draw ' => $ this ->request ->draw (),
972+ 'recordsTotal ' => $ this ->totalRecords ,
953973 'recordsFiltered ' => 0 ,
954- 'data ' => [],
955- 'error ' => $ error ? __ ($ error ) : "Exception Message: \n\n" .$ exception ->getMessage (),
974+ 'data ' => [],
975+ 'error ' => $ error ? __ ($ error ) : "Exception Message: \n\n" .$ exception ->getMessage (),
956976 ]);
957977 }
958978
@@ -1053,4 +1073,11 @@ protected function getPrimaryKeyName(): string
10531073 {
10541074 return 'id ' ;
10551075 }
1076+
1077+ public function editOnlySelectedColumns (): static
1078+ {
1079+ $ this ->editOnlySelectedColumns = true ;
1080+
1081+ return $ this ;
1082+ }
10561083}
0 commit comments