Closed virtualgadjo closed 5 months ago
I don't recommend to edit all columns with php. It may have slow down your application. Instead I would use javascript for this.
However, you can pass the variables inside a anonymous function with "use" keyword.
foreach($dts as $sl) {
$datatables->edit($sl, function($data) use ($sl ) {
return '<span data-col="' . $sl . ' ">' . $data[$sl] . '</span>';
});
}
Hi, and thanks a lot for your answer, great idea i hadn't thought about...
the problem is that once in the page i have already set a few data attributes to the tds and it works fine but i can't access the db column names i'll need to launch some custom editing modals linked to the line/row id (this works with js but not for the db column name which is different from the head th title)
and i agree i think that with your idea i'll be abble to edit only some column depending on their name (preg_)matchnig some string but your tool is so fast thet i've made a few trires editing all the column with the seame result
foreach($dts as $sl) {
$datatables->edit($sl, function($data) {
return '<span data-col="'foo">foo</span>';
});
}
and there was nearly no difference from the same table without editing (more than 22000 tds when displaying the full table - what should not happen...!) but sure, with specific data it may be a little slower
i use native queries without CI query builder and your adapter works faster than will coyote :)
i take the opportunity to thank you for this class i've been using since ci3 and that saved my life in many occasions :)
have a nice day
I'm really glad to hear this.
I can provide you one more example to look. This is using colreorder plugin (I just chose this example, it doesn't needed for what I want to show), which allows the columns order positions can be changed, both the data and the search inputs can change accordingly.
https://datatables.ozdemir.be/colreorder
Btw, it is possible to define the columns by their names, they match with the data.
// DataTable
var table = $('#example').DataTable({
"serverSide": true,
"responsive": true,
"colReorder": true,
"ajax": "ajax/colreorder.php",
"columns": [
{"data": "TrackId"},
{"data": "Name"},
{"data": "Album"},
{"data": "MediaType"}
]
});
Moreover, you can order and edit columns like this:
// DataTable
var table = $('#example').DataTable({
"serverSide": true,
"responsive": true,
"colReorder": true,
"ajax": "ajax/colreorder.php",
"columns": [
{
"data": "Name",
render: function (data, type, row) {
return '<span data-col="Name">' + data + '</span>';
},
},
{"data": "TrackId"},
{"data": "Album"},
{"data": "MediaType"}
]
});
I know the example web pages are old, but I'm too lazy to update those :) just bear with them
hi, i wouldn't say lazy at all according to your kind of help 😀
and just for you to know i've set your previous tip with inherited variable and it works like a charm, i keep displaying 50 to 100 lines out of 356 (for now) with78 cols each, every cell havig its data-attribute in less than half a second and the whole table in less than one second, that will be even faster when choosing the cells that need to be edited
i sometimes use this column definition with datatables but the table i retreive will have more columns, the fifteen first won't change but due to the complexity of the tool i'm working on, instead of using a relational table between this one and another one containing 63 lines, for now... i alter the first one adding a col when an line is added to the second one, thus i can't define those cols in the datatables statement
i know could, writing dynamic js script in the page source code but i've tried and the result with three tables, two for the data and one for the relational thing (my usual way to work with mysql) makes the query far slower and thus the page too and i may need the page to reload after some cells modification which would make the tool a hell to use using your tip, this server side table behaves like a simple table with 100 lines and a few cols already in the page :)
fortunately, back to the usual relational model for the other tables of this tool but even if i had to hit myself on the head to use mysql like a firebase db in this case, being an old php/mysql guy i'm happy to prove they stay as good and nearly as fast as react (or even one i prefer, vue js) and nosql dbs :)
thank again and a lot for your help :)
have a nice day
hi, just a question that may seem silly... i'm trying to edit all the result collumns at once for later js usage but if i write
$dts being he array of all the names of the columns i get, of course undefined var $sl and if i try
"Too few arguments to function App\Controllers\Colors::App\Controllers\{closure}(), 1 passed and exactly 2 expected" (yes it is with CI4 :)) this second error makes me think i've missed something but i caon't find out, if ever you had a luminous idea... :)
of course i've tried $globals but without success
have a nice day