Datatable custom filtering with Server Side with Editor
Datatable custom filtering with Server Side with Editor
Hi,
I am having some trouble integrating some custom functionalities with Datatable and Datatable Editor at the same time.
Without server-side processing my current functionalities works perfectly but I want to be able to implement server-side filtering with Editor.
With server-side filtering these work:
1.Pagination
2.Global Search
3.Sorting
4.Row reorder
5.Dynamic Page length
With server-side filtering these don't work:
1.Custom column input filtering
2.Custom footer select filtering
My serverside script for Datatable and Editor:
Editor::inst($db, 'article_categories')
->fields(
Field::inst('article_categories.id')->validator('Validate::numeric'),
Field::inst('article_categories.name')->validator('Validate::notEmpty'),
Field::inst('article_categories.description'),
Field::inst('article_categories.rowOrder')->validator('Validate::numeric')
)
->on('preCreate', function ($editor, $values) {
if (!$values['article_categories']['rowOrder']) {
$next = $editor->db()->sql('select IFNULL(MAX(rowOrder)+1, 1) as next FROM article_categories')->fetch();
$editor->field('article_categories.rowOrder')->setValue($next['next']);
} else {
$editor->db()
->query('update', 'article_categories')
->set('rowOrder', 'rowOrder+1', false)
->where('rowOrder', $values['article_categories']['rowOrder'], '>=')
->exec();
}
})
->on('preRemove', function ($editor, $id, $values) {
$order = $editor->db()
->select('article_categories', 'rowOrder', array('id' => $id))
->fetch();
$editor->db()
->query('update', 'article_categories')
->set('rowOrder', 'rowOrder-1', false)
->where('rowOrder', $order['rowOrder'], '>')
->exec();
})
->process($request->all())
->json();
My client-side script:
Default config:
jQuery(function () {
$.extend(true, $.fn.dataTable.defaults, {
serverSide: true,
fixedHeader: true,
searchDelay: 800,
paging: true,
processing: true,
pageLength: 10,
info: true,
dom: "Blfrtip",
select: true,
responsive: true,
lengthMenu: [
[10, 25, 50, -1],
[10, 25, 50, "All"],
],
});
});
This question has accepted answers - jump to:
Answers
Datatable and Editor setup:
Custom functions:
When I set server-side to false the custom functionalities I need works perfectly but I need these with server-side processing as it will significantly improve overall performance . I would appreciate any help and suggestion.
Regards,
Shovon Choudhury
I see you're using Editor in your example, but our accounts aren't showing that you have a license, or that you have a trial. Is the license registered to another email address? Please can let us know so we can update our records and provide support.
Thanks,
Colin
Colin, Just to let you know Shovon is doing this work for me under my account/license. I am not skilled with JavaScript and commonly call on him to help. My live installation is a custom CMS I developed. We're attempting to transition it to Laravel framework. If necessary I can repost this under my account, however it would be easier to communicate back/forth with him due to my lack of skills.
Ah, thanks for letting us know, I've updated Shovon's account with that info. We'll take a look and report back,
Colin
I suspect the regex part of the column filtering is what is causing the problem here.
The server-side processing implementations we ship don't include support for regex filtering on the database, as it can be a real performance drag.
Could you try using:
please?
If it isn't that, are you able to give me a link to your page so I can take a look?
Thanks,
Allan
Thanks @allan , It resolved the issue. We need some more help regarding inline editing and keeping main pop up editor open when "Update" is clicked. We must mention we are using bs4 dist.
We are using a temporary fix which we don't exactly want:
I have tried the following option it works but other buttons, selection start to malfunction sometimes clicking do nothing:
Regards,
Shovon Choudhury
Hi Shovon,
The approach you've taken with the buttons looks correct. Where you have the comment:
This is where you would to Editor what row it should edit next. Do you want it to edit the same row again, or some other row? If some other, based on what logic?
Allan
@allan we need to be able to edit the existing one.
Steps:
1. We edit and submit data
2. Data should be stored in the DB
3. Then the editor should open up with existing id with newly updated data.
Please look into the inline editor issue as well. It happens when I inline edit something and on onBlur submit if click any other record during submission (quick select) it shows an error in console I mentioned earlier.
Regards,
Shovon Choudhury
Hi Shovon,
I believe this is doing what you're looking for. After the submission is complete (
submitComplete
) the row is re-edited. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.Cheers,
Colin
@colin Thanks for your reply. Unfortunately it's not populating old data with fields after the original one is submitted.
I have added a line to see if that if block is really working. It prints something like "row_1".
As I mentioned previously, we are using datatables.net-bs4 dist. I hope that doesn't make any issue.
Looking forward for your help.
Regards,
Shovon Choudhury
Hi Shovon,
Will give you the currently selected row index. You can pass that into the
edit()
method to trigger editing on the currently selected row.Allan
@allan I tried this previously but modifying it a bit it worked. We are still having trouble with inline editor.
When we try editing a cell through inline editor with onBlur:"submit" it submits the record but if I click on another record during blur effect I get console log with type error "g is undefined".
I have tried:
This won't work without enter. Need your help.
Hi Shovon,
Using
this
(being atd
) with server-side processing won't work. You need to use the cell index - see this example for how to do that.If that doesn't do the job (it should ) can you give me a link to a page showing the issue so I can debug it please.
Thanks,
Allan
@allan Thank you so much. It worked!
@allan now the rowreorder isn't reordering properly. I am implementing it with serverside processing. What am I doing wrong here?
Here is the serverside setup:
@allan I got it resolved. I had the wrong ordering. I just added the order option and it worked like a charm.
Thanks a lot for your help.