@@ -76,6 +76,11 @@ public function __construct(Repository $config, Factory $view, HtmlBuilder $html
7676$ this ->tableAttributes =$ this ->config ->get ('datatables-html.table ' , []);
7777 }
7878
79+ /**
80+ * Sets the smart datatable class name.
81+ *
82+ * @var this
83+ */
7984public function setSmartDataTable ($ className )
8085 {
8186$ this ->smartDataTable =$ className ;
@@ -112,12 +117,38 @@ public function generateScripts()
112117 );
113118 }
114119
120+ /**
121+ * Get the "url" from the ajax attribute.
122+ *
123+ * @return string
124+ */
115125public function getAjaxUrl ()
116126 {
117127return is_array ($ this ->ajax ) ?$ this ->ajax ['url ' ] :$ this ->ajax ;
118128 }
119129
120- public function getQueryString ()
130+ /**
131+ * Set the "url" of the ajax attribute.
132+ *
133+ * @return this
134+ */
135+ public function setAjaxUrl ($ url )
136+ {
137+ if (is_array ($ this ->ajax )) {
138+ $ this ->ajax ['url ' ] =$ url ;
139+ }else {
140+ $ this ->ajax =$ url ;
141+ }
142+
143+ return $ this ;
144+ }
145+
146+ /**
147+ * Prepares the query string to use on ajax.
148+ *
149+ * @return string
150+ */
151+ public function prepareQueryString ()
121152 {
122153if ($ this ->hasCustomTableId ()) {
123154$ separator =str_contains ($ this ->getAjaxUrl (),'? ' ) ?'& ' :'? ' ;
@@ -136,17 +167,16 @@ public function getQueryString()
136167return '' ;
137168 }
138169
139- public function buildAjax ()
170+ /**
171+ * Builds the ajax url with the required query string parameters.
172+ *
173+ * @return void
174+ */
175+ public function prepareAjax ()
140176 {
141- $ queryString =$ this ->getQueryString ();
142-
143- if (is_array ($ this ->ajax )) {
144- $ this ->ajax ['url ' ] =$ this ->ajax ['url ' ].$ queryString ;
145- }else {
146- $ this ->ajax =$ this ->ajax .$ queryString ;
147- }
177+ $ queryString =$ this ->prepareQueryString ();
148178
149- return $ this ->ajax ;
179+ $ this ->setAjaxUrl ( $ queryString ) ;
150180 }
151181
152182/**
@@ -156,8 +186,6 @@ public function buildAjax()
156186 */
157187public function generateJson ()
158188 {
159- $ this ->buildAjax ();
160-
161189$ args =array_merge (
162190$ this ->attributes , [
163191'ajax ' =>$ this ->ajax ,
@@ -186,9 +214,8 @@ public function parameterize($attributes = [])
186214$ values = [];
187215$ replacements = [];
188216
189-
190217foreach (array_dot ($ parameters )as $ key =>$ value ) {
191- if ($ this ->isCallbackFunction ($ value ,$ key ) || $ this -> isJavascriptFunction ( $ value , $ key ) ) {
218+ if ($ this ->isCallbackFunction ($ value ,$ key )) {
192219$ values [] =trim ($ value );
193220array_set ($ parameters ,$ key ,'% ' .$ key .'% ' );
194221$ replacements [] ='"% ' .$ key .'%" ' ;
@@ -218,18 +245,6 @@ protected function isCallbackFunction($value, $key)
218245return Str::startsWith (trim ($ value ),'function ' ) || Str::contains ($ key ,'editor ' );
219246 }
220247
221- /**
222- * Check if given key & value is a valid callback js function.
223- *
224- * @param string $value
225- * @param string $key
226- * @return bool
227- */
228- protected function isJavascriptFunction ($ value ,$ key )
229- {
230- return Str::startsWith (trim ($ value ), ['$ ' ,'$. ' ,'function ' ]);
231- }
232-
233248/**
234249 * Get javascript template to use.
235250 *
@@ -587,6 +602,8 @@ public function ajax($attributes = '')
587602 {
588603$ this ->ajax =$ attributes ;
589604
605+ $ this ->prepareAjax ();
606+
590607return $ this ;
591608 }
592609