Quantcast
Channel: Recent Discussions — DataTables forums

Follow up to "Datatables defaults on datatable fields in Editor"

$
0
0

As I marked the question as answered, I will follow up here...

Following this up, seems like layout is where I have my issues..
My default settings are

                top: [
                    'buttons',
                    'paging',
                    { search: { placeholder: 'Sökord' } }
                ],
                topStart: null,
                topEnd: null,
                bottomStart: 'info',
                bottomEnd: 'pageLength'

This gets overridden by

                top: hasButtons
                    ? ['search', 'buttons', 'info']
                    : ['search', 'info'],
                bottom: ['paging'],
                bottomStart: null,
                bottomEnd: null,
                topStart: null,
                topEnd: null

It does not seem to be possible to override this in the datatable field type options.
I tried with

                            top: [
                                'buttons'
                            ]

but to no avail.
KR,
Björn H


rowReorder has started adding extra rows

$
0
0

Link to test case: https://www.wd4g.com/WCGateway/rowReorder_Debug.wc
Debugger code (debug.datatables.net): n\a
Error messages shown: no error message
Description of problem:
rowReordering was working fine until recently, now each time we do a rowReorder (or just drag the row to the top of the dt) we get a new rows inserted above the actually data rows (but below the column headers), this new row contains the datatables_length elements, and the datatable_filter elements. Also, we get a new rows below the data rows, (but above the table footer), this row contains the datatable_info and datatable_pagnation elements. This happen for each rowReOrder, so it duplicates each time.

I have tried removing all recent global changes to do with datatables, but the issue remains.

So, I'm struggling to find the cause of this issue.
If someone could please take a look and offer any advice that would be really appreciated.

Thanks, Chris

Searching a table which contain tinyint values?

$
0
0

Can I search table data rows which have tinyint values?
Scenario: A table contains people. A table column is for marital status. 0=not married, 1=married. Please note that the information is not in text format.
How can I search using datatable and fetch the married people or the opposite?
Any example?
Thank you

How do you incase the table, and bottom row, in a div? but leave out the top?

$
0
0

This might be a dumb question but i want to incase the table itself and the bottom row in a div, but leave out the top row?

is there an easy why to do that with layout?

something like this:

<div class="dt-search"> search</div>
<div class="card">
   <div class="dt-table"></div>
   <div class="dt-bottom-row"></div>
</div>

again sorry if its a stupid question

search highlighting using mark.js

$
0
0

I would like to implement search highlighting using mark.js with DataTables 2
https://datatables.net/blog/2017/search-highlighting-with-markjs#Adding-custom-mark.js-options

JS Bin test case
https://live.datatables.net/teripiyu/1/edit

I want to add custom mark.js options, such as wildcard search, but it only works when I trigger the search manually.

$("#example").mark("R*os", {
    wildcards: "enabled",
    caseSensitive: true
});

Using the same settings to initialize the DataTable, the search functionality in the search field is not working when typing.

var table = new DataTable('#example',
 { mark:
    {  wildcards: "enabled",
      caseSensitive: true
    }
 }                         
);

How to rotate cell text and adjust it's height?

$
0
0

I would like to rotate the text in certain cells by -90 degrees, as they are currently taking up too much space in width.

For testing purposes, I tried:

<span style="transform: rotate(-90deg);display: inline-block;">My Vertical Text</span>

It works well, except that the height of the cell is not adjusted and all the text ends up overlapping (see capture)

What is the correct way to do this? Thank you.

Column Control appears two times

$
0
0

Hello,

I'm not new to DataTables.

But recently in a small project I wanted to use Column Control plugin. Everything works perfectly except that those controls are appear two times per column.

Any hints how to debug ?

Maybe something is called twice ? But could not figure it out yet. It is simple php file (twig Templates) which loads 4 rows from the database.

new DataTable("#test-table",{
    paging: true,
    searching: false,
    columnControl: ['order', 'colVisDropdown',['searchList']],
    ordering: {
        indicators: false
    }
});

Date picker with jQuery UI

$
0
0

Hi, am I the only one experiencing an error with the date picker?

Example: https://editor.datatables.net/examples/dates/dates.html

When I select "DataTables" as the framework, everything works fine.
However, when I select "jQuery UI" as the framework, the direct selection of a month or year in the date picker no longer works. The selection box flashes briefly and then disappears immediately.

This issue occurs with the Firefox browser (143.0.3).
Chrome (140.0.7339.208) doesn’t seem to be affected.


Database showing error code 18 what should I do to removeit

$
0
0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Query - for Help and better solution

$
0
0

**https://live.datatables.net/ciyuride/21/edit**:

At the above 'test case'

Add a content before the current text

only if the first row contains a 'specific word'.(there use '36' and another is '$2,')

It is working for the first page only.

So the query is

1- How to loop through the entire table ?

2- Whether the Javascript works well on all browsers (old and modern) ?

3- Any better method to tiny up the said Javascript ?

4- Unable to change the table cell values from the default values to check that what will happen if the same mentioned values '36' is available on two different column.

Looking forward for a solution.

george

Inline editing and tag fields

$
0
0

Hi Allan,

I'll continue here (from https://datatables.net/forums/discussion/81422/date-picker-with-jquery-ui
).

When I use inline editing for tag fields and clicking on 'Add' expands the selection list. As soon as I select an entry from the list, the tag editor disappears without saving the new value.

I extended the tags-multiple example with added "keytable".

Here is the code:

var editor = new DataTable.Editor({
    ajax: '../../controllers/joinArray.php',
    fields: [
        {
            label: 'First name:',
            name: 'users.first_name'
        },
        {
            label: 'Last name:',
            name: 'users.last_name'
        },
        {
            label: 'Site:',
            name: 'users.site',
            type: 'select'
        },
        {
            label: 'Permissions:',
            name: 'permission[].id',
            type: 'tags',
            limit: 4
        }
    ],
    table: '#example'
});

$('#example').DataTable({
    ajax: {
        url: '../../controllers/joinArray.php',
        type: 'POST'
    },
    columns: [
        { data: 'users.first_name' },
        { data: 'users.last_name' },
        { data: 'sites.name' },
        { data: 'permission', render: '[, ].name', editField: 'permission[].id'}
    ],
    keys: {
        columns: [0,1,3],
        editor: editor
    },  
    layout: {
        topStart: {
            buttons: [
                { extend: 'create', editor: editor },
                { extend: 'edit', editor: editor },
                { extend: 'remove', editor: editor }
            ]
        }
    },
    select: true
});

best regards
Ilja

Editor Ajax URL Replacement not working for uploads

Has anyone incorporated the softdelete example into the parentchild datatables example?

$
0
0

I think this is due to the dynamic nature of the child datatables in the parentChild example.
Apologizes if this has been answered previously, but I did not find anything in the search.

The line in the below code that is the issue (I think) is ' var rows = DataTables_Table_0.rows({ selected: true }).indexes();' which does not work. I attempted using the ID from inspect since there is no obvious instantiation of the datatable in question (at least that I can see).

Any ideas?

Thanks in advance!

{
label: 'Users:',
name: 'users.site',
type: 'datatable',
editor: usersEditor,
submit: false,
optionsPair: {
value: 'users.id'
},
config: {
ajax: {
url: '../controllers/NEWuser/users.php',
type: 'post',
data: function (d) {
if (siteTable) {
var selected = siteTable.row({ selected: true });
if (selected.any()) {
d.site = selected.data().id;
}
}
}
},
buttons: [
{ extend: 'create', editor: usersEditor },
{ extend: 'edit', editor: usersEditor },
//{ extend: 'remove', editor: usersEditor }

        {
        extend: 'selected',
        text: 'Delete',
        action: function (e, dt, node, config) {


            var rows = DataTables_Table_0.rows({ selected: true }).indexes();

            usersEditor
                .hide(usersEditor.fields())
                .one('close', function () {
                    setTimeout(function () {
                        // Wait for animation
                        usersEditor.show(usersEditor.fields());
                    }, 500);
                })
                .edit(rows, {
                    title: 'Delete',
                    message:
                        rows.length === 1
                            ? 'Are you sure you wish to delete this row?'
                            : 'Are you sure you wish to delete these ' +
                              rows.length +
                              ' rows',
                    buttons: 'Delete'
                })
                .val(
                    'removed_date',
                    new Date().toISOString().split('T')[0]
                );
        }
    }                  

    ],
    columns: [
        {
            data: 'users.first_name',
            title: 'First name'
        },
        {
            data: 'users.last_name',
            title: 'Last name'
        },
        {
            data: 'users.phone',
            title: 'Phone'
        }
    ]
}

}

Row animation missing after ajax.reload()

$
0
0

I'm trying to implement a branded row animation (e.g., fade-in or highlight) after calling table.ajax.reload(null, false) in DataTables. The goal is to visually indicate updated rows after an AJAX refresh.

I've placed the animation logic inside drawCallback, and confirmed via console.log that the callback executes. However, the animation doesn't visibly trigger — even though the class is applied.

$(document).ready(function () {
    usersTable = $('#usersTable').DataTable({
        ajax: {
            url: '/Admin/GetUsersAjax',
            type: 'GET',
            dataSrc: function (json) {
                console.log("AJAX response received:", json);
                return json.data;
            },
            error: function (xhr) {
                console.error("DataTables AJAX error:", xhr.responseText);
                alert("Failed to load user data.");
            }
        },
        drawCallback: function (settings) {
            console.log("drawCallback triggered");

            $('#usersTable tbody tr').each(function () {
                const row = $(this);
                row.removeClass('row-animate');
                void row[0].offsetWidth; // force reflow
                row.addClass('row-animate');
                console.log("Animation class applied to row:", row.text());
            });
        },
        order: []
    });

    // Optional: clean up after animation
    $('#usersTable').on('animationend', 'tr.row-animate', function () {
        $(this).removeClass('row-animate');
        console.log("Animation class removed after animationend");
    });
});
function PopupForm(url) {
    console.log("PopupForm called with URL:", url);

    var formDiv = jQuery('#masterModal');

    jQuery.get(url, function (response) {
        console.log("PopupForm GET response received:", response);

        if (response.trim().length > 0) {
            jQuery('#modalBody').html(response);
            formDiv.modal('show');
            console.log("Modal shown with content.");
        } else {
            console.warn("Modal content is empty. Skipping modal popup.");
        }
    }).fail(function (xhr) {
        console.error("PopupForm GET failed:", xhr.responseText);
    });
}

function SubmitForm(form) {
    console.log("SubmitForm triggered for form:", form);

    jQuery.validator.unobtrusive.parse(form);
    console.log("Validation parsed.");

    if (jQuery(form).valid()) {
        console.log("Form is valid. Submitting via AJAX...");

        jQuery.ajax({
            type: 'POST',
            url: form.action,
            data: jQuery(form).serialize(),
            success: function (data) {
                console.log("AJAX POST success:", data);

                if (data.success) {
                    if (document.activeElement) {
                        document.activeElement.blur();
                        console.log("Active element blurred.");
                    }

                    $('#masterModal').modal('hide');
                    console.log("Modal hidden after success.");

                    usersTable.ajax.reload(function () {
                        console.log("DataTable reloaded.");

                        const nodes = $(usersTable.rows().nodes());
                        console.log("Table rows fetched:", nodes.length);

                        nodes.each(function () {
                            const rowData = usersTable.row(this).data();
                            console.log("Checking row:", rowData);

                            if (rowData && String(rowData.UserID) === String(data.newUserID)) {
                                console.log("Matching row found. Applying animation.");
                                $(this).addClass('new-row-animate');

                                setTimeout(() => {
                                    $(this).removeClass('new-row-animate');
                                    console.log("Animation class removed after timeout.");
                                }, 1500);
                            }
                        });
                    }, false);

                    jQuery.notify(data.message, {
                        globalPosition: 'top center',
                        className: 'success'
                    });
                } else {
                    console.warn("Server returned error state:", data.message);
                    $('#modalBody').html(data.html);

                    jQuery.notify(data.message, {
                        globalPosition: 'top center',
                        className: 'error'
                    });
                }
            },
            error: function (xhr) {
                console.error("AJAX POST failed:", xhr.responseText);

                jQuery.notify("Server error occurred", {
                    globalPosition: 'top center',
                    className: 'error'
                });
            }
        });
    } else {
        console.warn("Form validation failed.");
    }

    return false;
}
/* Animation for adding new row in table */
@keyframes rowFlash {
    0% {
        background-color: #c6f6d5;
    }

    50% {
        background-color: #90ee90;
    }

    100% {
        background-color: transparent;
    }
}

#usersTable tbody tr.new-row-animate {
    animation: rowFlash 1.2s ease-in-out;
}

Any help would be greatly appreciated!

After updating a datatable row return to the page where the row belongs.

$
0
0

Suppose I have a table with many rows and by clicking to i.e. page 40 I update a row through my application's menu.
I would like to know how I should handle such a situation so that after the row's update to be able to return to the page where the row was found. How can I achieve that? Any example? My project is a Laravel project if this helps at all.
Thanks


Column width issues in DT 2.3.5

$
0
0

Link to test case:
https://live.datatables.net/zetukeke/3/edit

Description of problem:
Thanks for a great product that makes life good :-)

When switching to the latest release of DT, 2.3.5, my tables got a bit messed up. I have boiled it down to the cases demonstrated in the test case.

I think things went wrong in this commit:
https://github.com/DataTables/DataTablesSrc/commit/8b2d742ca039f06ed2724bb5b4c25577c50393bd

In version 2.3.4 (try to swap in the test case), the longest string used to calc the column width was the cellString, whereas in the new version it is the stripped HTML string from cellString that is used and any formatting get lost. Also, the new function with 3 longest string parts seem to cause some trouble in the case where the string includes numeric character reference (and maybe more).

I hope this helps you on the way to the solution!

Editor validator $host

$
0
0

From: https://editor.datatables.net/manual/php/validation#Custom-field-validators

Is there an example of what $host does?

Field::inst( 'last_name' )
    ->validator( function ( $val, $data, $field, $host ) {
        return strlen( $val ) > 50 ?
            'Name length must be 50 characters or less' :
            true;
    } );

Can I access the database with that?

Right now I'm doing the below but was wondering if $host offered a different option:

Field::inst( 'last_name' )
    ->validator( function ( $val, $data, $field, $host ) use ($db) {
        
        $db->stuff();
        
        return strlen( $val ) > 50 ?
            'Name length must be 50 characters or less' :
            true;
    } );

! symbol not filtering table

$
0
0

Link to test case: https://datatables.net/examples/api/multi_filter.html
Debugger code (debug.datatables.net): -
Error messages shown: -
Description of problem: When inserting search value "!" or how many you like it dose not start filtering.
Feels like a bug because it accepts different symbols like ?, <, : and etc. Or is there ignore symbols list somewhere that i have not found.

And how does search work with space? whem im entering "1 2 3 4 5" its filter like "1 or 2 or..." but if i enter "38 33" it filter all out. (Same example- age)

Unable to get columnControl working

$
0
0

I have my table set up and working correctly using the code below, but whenever I add
columnControl: ['order', ['searchList']]

I get the following error
Cannot read properties of null (reading 'appendChild')

Code

    let mainConfig = {
        ordering: true,
        order: [[0, 'asc'], [1, 'asc']],
        info:     true,
        responsive: true,
        pagingType: "simple_numbers",
        pageLength: 25,
        draw: 1,
        autoWidth: true,
        dom: "<'row'<'#col2.col-xs-12 col-md-6 text-right'fB><'#col1.col-xs-12 col-md-6 text-muted'i>>rt<'bottom'lp><'clear'>",
        buttons: [
            {
                extend: 'csv',
                title: 'CSV File - ' + moment(new Date()).format('YYYY.MM.DD')
            }
        ],
        data: data,
        columnControl: ['order', ['searchList']],
        columns: [
            { data: 'one', className: "text-capitalize", title: 'one' },
            { data: 'two', className: "text-capitalize", title: 'two' },
            { data: 'three', title: 'three' }
        ]
    }

    $('#my-datatable').dataTable(mainConfig).api();

If I take out the columnControl the table loads fine

I have the CSV button extension working fine. Note i am loading all CSS and JS files in the correct order

Search panes options disappearing when custom filter used

$
0
0

Link to test case:
https://live.datatables.net/tikaloxu/3/
Debugger code (debug.datatables.net):
n/a
Error messages shown:
n/a
Description of problem:
I'm trying to use search panes with a custom filter for date ranges as described here.

They work fine separately, but when I apply a date filter it removes all the options in the search pane.

How can I get them to stay available when a date filter is applied?

Refresh ColumnControl SearchList values based on current values in a column

$
0
0

Is it possible for the values in each ColumnControl SearchList to change depending on the current data available in each column?

Example
If you had two columns "Job" and "Location". If you were to filter the Job column and select "Developer", it would be good to only see the values in the Location column which were available the for Developer job.

My current setup
I have ColumnControl SearchList setup on a few columns in my table. When I select a value from one of the columns, I can then select a value in another column which returns no rows.

Can I add an if-construction while rendering?

$
0
0

I see some options for adding an If construction while rendering, see https://datatables.net/manual/data/renderers

But I can't figured it out how to add this one. I have now this render:

columns: [                
    { data: null, render: (data) => data.client.gender + ' ' + data.client.firstname + ' ' + data.client.lastname
    }
]

If the records hold this data:
Gender Firstname Lastname
M John Doe

Than I would like to have in the column Mister John Doe.

How to add the if-contruction into the render?

I have try to add ... => if (data.client.gender === 'M') { return Mister } but I get an error for using 'if'

Any idea how to achieve this?

Best regards,

Arie


ColumnControl won't keep state of search if two searches are present

$
0
0

Description of problem:
Hello guys,
my scenario is that I'm building a datatable with columncontrol (and much other extensions)
with this cc in the init stage:

columnControl: [
    {
        target: 0,
        content: [
            'order',
            ['orderAsc', 'orderDesc', 'orderAddAsc', 'orderAddDesc', 'orderRemove', 'orderClear', 'spacer', 'reorderLeft', 'reorderRight', 'spacer', 'search', 'searchList']
        ]
    },
    {
        target: 1,
        content: ['search'],
        className: 'dt-header-columnssearch'
    }
]

What I'm doing is hiding the second row and toggle it with a button (let's call that row - Quick Search)
and on the table header I did like a "Column Menu" with much stuff there.
now, one more thing is that -
when clicking on a datatable row it opens a modal dialog which has a callback.
on the callback I save a state using state restore extension then refreshing the page and loading the state i saved. let's call this action "Editing".

the problem is this.
1. When toggling the Quick Search and doing a search there, and then Editing, the state restored with the search and the table is filtered accordingly
2. When searching using the search in the column menu and then editing, it won't save the search nor will filter the table and it's like it resets the table

I need to fix that when using the search inside the Column Menu it will restore good after the refresh.

bonus question - is there a way to sync these searches inputs?

Thank you very much for the help in advance!

How to set a default selected value in SearchList on table initialization?

$
0
0

Hi,

I’m using DataTables 2 with the new columnControl + searchList features.
Everything is working, but I would like to pre-select a value in the SearchList when the table loads, while still allowing users to change the selection afterwards.

Here is a simplified version of my current configuration: https://live.datatables.net/jivapopa/1/edit

The table is filtered correctly on load, but the SearchList itself does not show “London” as selected.
I would like the SearchList UI to reflect the default filter selection.
And if I try to change the SearchList selection after the default filter is applied, it shows no results.

Any help or guidance would be appreciated — thanks!

Editor datetime input is malformed

$
0
0

The date input for the editor with bootstrap5 styling and floating labels is malformed. It has two overlapping input boxes.
You can see it at the example itself

Reference to buttons.name in config

$
0
0

Is it possibe to use the buttons.name setting to activate a set of buttons in a layout definition? (like 'buttons:main' or similar)
I would like to define multiple sets of buttons in the default settings and be able to refer to them in the config locally, but maybe this needs to be done through API calls after config?
KR, Bjørn H

class

Change of height in BS5 2.3.3 breaks header height

$
0
0

In the BS5 theme in 2.3.3 the header height was changed from 20px to 24px:

table.dataTable thead > tr > th.dt-orderable-asc span.dt-column-order, table.dataTable thead > tr > th.dt-orderable-desc span.dt-column-order, table.dataTable thead > tr > th.dt-ordering-asc span.dt-column-order, table.dataTable thead > tr > th.dt-ordering-desc span.dt-column-order,
table.dataTable thead > tr > td.dt-orderable-asc span.dt-column-order,
table.dataTable thead > tr > td.dt-orderable-desc span.dt-column-order,
table.dataTable thead > tr > td.dt-ordering-asc span.dt-column-order,
table.dataTable thead > tr > td.dt-ordering-desc span.dt-column-order {
  position: relative;
  width: 12px;
  height: 24px;
}

This increases the header height by 4px making it different from all the other table rows. Please revert this change.

Custom ColumnControl filters

$
0
0

The current ColumnControl filters for text include contains, notContains, equal, notEqual, start, ends, empty, and notEmpty.

I have a specific case where I need notStarts and notEnds. From what I've seen, there are no options in the documentation or source code.

Would it be a good idea to add an option to add custom filters or add these filters to the default options?

I am willing to contribute if necessary.


editor.tinymce.js not auto-resizing on init with tinymce version 8

$
0
0

autosize on initialization worked with the plugin and tinymce 5

now with tinymce 8 the editor does not expand when displayed, only when users add a line break

AI could not provide a fix



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>