@@ -46,6 +46,8 @@ class DataProcessor
4646
4747 protected bool $ ignoreGetters = false ;
4848
49+ protected string $ indexColumn ;
50+
4951 public function __construct (protected iterable $ results , array $ columnDef , protected array $ templates , protected int $ start = 0 )
5052 {
5153 $ this ->appendColumns = $ columnDef ['append ' ] ?? [];
@@ -58,6 +60,7 @@ public function __construct(protected iterable $results, array $columnDef, prote
5860 $ this ->makeHidden = $ columnDef ['hidden ' ] ?? [];
5961 $ this ->makeVisible = $ columnDef ['visible ' ] ?? [];
6062 $ this ->ignoreGetters = $ columnDef ['ignore_getters ' ] ?? false ;
63+ $ this ->indexColumn = (string ) Config::get ('datatables.index_column ' , 'DT_RowIndex ' );
6164 }
6265
6366 /**
@@ -68,7 +71,6 @@ public function __construct(protected iterable $results, array $columnDef, prote
6871 public function process ($ object = false ): array
6972 {
7073 $ this ->output = [];
71- $ indexColumn = (string ) Config::get ('datatables.index_column ' , 'DT_RowIndex ' );
7274
7375 foreach ($ this ->results as $ row ) {
7476 $ data = Helper::convertToArray ($ row , ['hidden ' => $ this ->makeHidden , 'visible ' => $ this ->makeVisible , 'ignore_getters ' => $ this ->ignoreGetters ]);
@@ -79,7 +81,8 @@ public function process($object = false): array
7981 $ value = $ this ->removeExcessColumns ($ value );
8082
8183 if ($ this ->includeIndex ) {
82- $ value [$ indexColumn ] = ++$ this ->start ;
84+ $ value [$ this ->indexColumn ] = ++$ this ->start ;
85+ $ value = $ this ->editIndexColumn ($ value , $ row );
8386 }
8487
8588 $ this ->output [] = $ object ? $ value : $ this ->flatten ($ value );
@@ -120,13 +123,38 @@ protected function addColumns(array $data, $row): array
120123 protected function editColumns (array $ data , object |array $ row ): array
121124 {
122125 foreach ($ this ->editColumns as $ value ) {
126+ if ($ this ->includeIndex && $ value ['name ' ] === $ this ->indexColumn ) {
127+ continue ;
128+ }
129+
123130 $ value ['content ' ] = Helper::compileContent ($ value ['content ' ], $ data , $ row );
124131 Arr::set ($ data , $ value ['name ' ], $ value ['content ' ]);
125132 }
126133
127134 return $ data ;
128135 }
129136
137+ /**
138+ * Edit index column after it has been added to the row.
139+ */
140+ protected function editIndexColumn (array $ data , object |array $ row ): array
141+ {
142+ if (! $ this ->includeIndex ) {
143+ return $ data ;
144+ }
145+
146+ foreach ($ this ->editColumns as $ value ) {
147+ if ($ value ['name ' ] !== $ this ->indexColumn ) {
148+ continue ;
149+ }
150+
151+ $ value ['content ' ] = Helper::compileContent ($ value ['content ' ], $ data , $ row );
152+ Arr::set ($ data , $ this ->indexColumn , $ value ['content ' ]);
153+ }
154+
155+ return $ data ;
156+ }
157+
130158 /**
131159 * Setup additional DT row variables.
132160 */
0 commit comments