Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all 82534 articles
Browse latest View live

Checkbox to hide/ unhide rows in the table (after Ajax Request)

$
0
0

Hi,

I love the datatables framework, but have used it for very standard things so far. I am currently stuck trying to implement a Check box which will hide/ unhide rows in a populated Data Table (via a periodic Ajax.reload()) based on a search in a specific column.

After reviewing the API and other forum items, it looks like l need the columns.search functionality.

               var eventTable = $('#event-table').DataTable({
                    "processing": true,
                    "serverSide": true,
                    "ajax": {
                        url: '<?php echo $_SERVER['PHP_SELF']; ?>',
                        method: "POST",
                        data: {

                . ..  . .... ... other code .........
                // Set the Interval Poller
                setInterval(function () {
                    eventTable.ajax.reload();
                    // Set the time inside the browser
                    var localTime = getLocalBrowserTimeAsString();
                    $('#last_refreshed_time').text(localTime);
                }, <?php echo $AUTO_REFRESH_PERIOD * 1000; ?>);

                // Set the Hide completed Event listenter
                $('#hide_completed').change(function () {
                    if (this.checked) {
                        //  NOT WORKING - DOES NOTHING
                        eventTable.column(0).search('WEST').draw();
                    } else {
                        //  NOT WORKING - DOES NOTHING
                        eventTable.column(0).search('EAST').draw();
                    }
                });

I used both column(0).search and columns(0).search, but neither appear to do anything and there are no javascript exceptions being thrown.

Three questions:

1) what am l doing wrong above?
2) how would l use the RegEx functionality to search for anything not equal to 'WEST'?
3) how do l hold state, so that when the Ajax.reload() request happens, that the checkbox-filter remains?

Any help that you can provide would be gratefully appreciated .. since l am tearing my hair out .. trying to get this done.


How to change the search language option dynamically

$
0
0

I've been trying without success to change the search language option of an already initialized/drawn datatable object ... as far as I understood it should be possible .. but I only get errors (not a function, undefined, uncaught,..).. any suggestion?

Wonky icons for bootstrap 4 depending on header wrapping and page size (Edge and IE)

How to fix the compatibility problems with Chrome 69.0.3497.81 ?

$
0
0

Hi,
we noticed a problem visualizing tables made with DataTables using as browser Chrome 69.0.3497.81.
Clicking on a row the text in the row disappears, independly from CSS.
Any idea?
Best Regards

example error

Page/Paging number color styles

$
0
0

Hi all!

I am having a very difficult time finding the .css switch/trigger for changing the page/paging background for both default and non-selected colors.

I have downloaded and reviewed (implemented) all of the example css from this example:

https://datatables.net/blog/2011-05-10#Sorting-and-paging

For the life of me, I cannot find how they were able to change the background and/or default color of the page/paging colors.

I know it must be very simple, I am just missing it! Any help would be most appreciated!!! :smile:

Thank you and Kind Regards,
Jason

Question about changing alphanumeric ordering on a datatable

$
0
0

hello. Hopefully this question hasn't been asked. It seems like when an alphanumeric field is in ascending order it is in order by 1-9 and then A-Z. is there a way to change it so that it is A-Z and then 1-9?

Thanks

Loss of data when exporting, using fnRowCallback to modify the table exporting Definiciones de expor

$
0
0

Hi, I have a problem with the export buttons.

I use 'fnRowCallback' to modify data in the table, and when exporting to PDF, csv, etc, this data does not take them.

I use ajax to get the data.

any ideas? Maybe some missing parameter?


Hidden column reappears after refreshing table

$
0
0

After updating table data and calling .draw(), a previously hidden column reappears intermittently. Any ideas what might be causing this? See the column to the far right.

Data Table and Export using Sharepoint REST

$
0
0

I have a Data Table that pulls information from a Sharepoint list using REST.
I want to export this list to Excel (reason for using data table is it is not limited by 5000 items)
below is my code but the button is not working.
In the example, it does not show putting a Button HTML in the code so I am not sure if the script creates the button itself.

$(document).ready( function() { $('#example').DataTable( { dom: 'Bfrtip', buttons: [ { extend: 'excelHtml5', customize: function( xlsx ) { var sheet = xlsx.xl.worksheets['sheet1.xml']; $('row c[r^="C"]', sheet).attr( 's', '2' ); } } ] } ); } ); function LoadZipCodes(state) { var ItemVType = document.getElementById("VType").value; var call = $.ajax({ url: "https://mysite/_api/Web/Lists/GetByTitle('SpendPlanRollup')/items?&$filter=(FiscalYear eq '"+state+"')and(Appropriation eq'"+ItemVType+"')&$top=6000", type: "GET", dataType: "json", headers: { Accept: "application/json;odata=verbose" }, }); call.done(function (data,textStatus, jqXHR){ $('#example').dataTable({ "bDestroy": true, "bProcessing": true, "aaData": data.d.results, "oLanguage": { "sSearch": "Filter Records: " }, "aoColumns": [ { "mData": "MDEP" }, { "mData": "State" }, { "mData": "Sub_x0020_Program" }, { "mData": "State_x0020_Priority" }, { "mData": "ARNG_x0020_PM_x0020Priority" }, ] }); }); call.fail(function (jqXHR,textStatus,errorThrown){ alert("Error retrieving Tasks: " + jqXHR.responseText); }); }

Custom sort function not called onLoad of Jquery datatable

$
0
0

I have added a custom sort functionality in datatable. It works fine when the table header is clicked. However, On pageLoad I want the table to be sorted by that column using the same logic as provided in the custom sort function. It does not seem to do so. Here is my code snippet

$(document).ready(function(){
  $("#stripedTableAcp").DataTable({
    "columnDefs": [
      { 
        "type": "acp_name",
        "targets": 3
      } 
    ],
    "order": [[ 3, "asc" ]],
    "pageLength": 100,
    "lengthMenu": [100, 500, 1000, 2000, 5000]
  });

  $.fn.dataTableExt.oSort["acp_name-desc"] = function (x, y)
  {
    console.log("1");
    x = jQuery(x).text();
    y = jQuery(y).text();

    temp = x.split("-");
    xPart1 = temp[0];
    xPart2 = parseInt(temp[1]);

    temp = y.split("-");
    yPart1 = temp[0];
    yPart2 = parseInt(temp[1]);

    if(xPart1 > yPart1)
    {
      return -1;
    }

    if(xPart2 > yPart2)
    {
      return -1;
    }

    return 1;
  };

  $.fn.dataTableExt.oSort["acp_name-asc"] = function (x, y)
  {
    console.log("2");
    x = jQuery(x).text();
    y = jQuery(y).text();

    temp = x.split("-");
    xPart1 = temp[0];
    xPart2 = parseInt(temp[1]);

    temp = y.split("-");
    yPart1 = temp[0];
    yPart2 = parseInt(temp[1]);

    if(xPart1 > yPart1)
    {
      return 1;
    }

    if(xPart2 > yPart2)
    {
      return 1;
    }

    return -1;
  }
});

Please note that the console.log added to the function is fired when the table header is clicked but not upon page load

datatable version is 1.10.19 as provided by the CDN

Any help is greatly appreciated.

Custom Row and Column Visibility change

$
0
0

Hi there,
I'm adding a custom row to the header in order to allow per column search. Unfortunately the cells of this row are not being removed when the column visibility is changed. I wasn't able to find any solution/workaround for this issue. Are you aware of a possible solution?

Basically this is what happens:

                buttons: [
                    {
                        extend: 'colvis'
                    }
               ]
                initComplete: function () {
                    if (searchAndFilter) {
                        const table = this.api().table();
                        const row = $('<tr class="searchFilter-action"></tr>').appendTo(table.header());
                        this.api().columns().every(function () {
                            const column = this;
                            const cell = $('<th></th>')
                                .appendTo(row);
                            const classNames = columns[column.index()].className;
                            if (classNames && classNames.includes('action-search')) {
                                $('<input type="text" placeholder="Search..." data-index="' + column.index() + '" />')
                                    .appendTo(cell)
                                    .on('keyup', function () {
                                        column
                                            .search(this.value)
                                            .draw();
                                    });
                            } else if (classNames && classNames.includes('action-filter')) {
                                const select = $('<select><option value=""></option></select>')
                                    .appendTo(cell)
                                    .on('change', function () {
                                        const val = $.fn.dataTable.util.escapeRegex(
                                            $(this).val()
                                        );

                                        column
                                            .search(val ? '^' + val + '$' : '', true, false)
                                            .draw();
                                    });

                                column.data().unique().sort().each(function (d, j) {
                                    select.append('<option value="' + d + '">' + d + '</option>')
                                });
                            } else {
                                $('<span></span>')
                                    .appendTo(cell)
                            }
                        });
                    }
                }

DataTables Editor capabilities

$
0
0

Hi all,

I'm new using DataTables, and I would like to know if when you are using all features for the DataTable Editor, is it possible to somehow set up the delete, update, edit, create, details to use my web api to handle the api calls?

Like setup the DataTable ajax url to execute my web api method?

If its possible, how would be the setup for it?

If not, how DataTables would handle the CRUD operations saving everything into the database?

Also, my web api is made in Python and Django Rest Framework.
Is it possible when listing records (using some view) to use Django's pagination feature and lazy loading?

Thank you very much!

Regards,
Alex

Should I limit the number of items (rows) of data I have per table?

$
0
0

I'm engineering a massive research website, and have about 4,000 or so rows of data to input. I'm wondering how many rows of data I can put in one table, so I don't slow down the search or sort abilities? I'm using Javascript to source the data, not AJAX.

I can organize my data into smaller sections of individual tables. I'm not sure where to draw the line per table. Pun intended haha :)

Where do I start to create a searchable, sortable table w/expandable rows?

$
0
0

Is there a place where I can get sample code for a table with searchable content plus sortable columns and expandable rows to show hidden content when clicked? I actually already have my content in two different tables, one is searchable and sortable, and the other is expandable, but I came to DataTables hoping I could create a table with all 3 features. Thanks!


How to implement changing of page number in text field?

$
0
0

How would I implement this into the existing pagination controls? One of two options I can think of is to have the text field inbetween the first/previous and next/last buttons or have a text field pop up when you click on the ... buttons (like I have seen on other tables).

I have had a look at the input plugin but it seems you can't have and also include the first and last buttons (it also breaks the styling of the buttons). I have a general idea of how to do this manually but I'm wondering if anyone else has done this. Thanks.

How can we get data once click on pagination buttons ?

$
0
0

Dears,#

I can able to get the current page data by using following code.

var data = table.rows({ page: 'current' }).data();

Above code give the content of the current page(Example 10 data). But when I click on pagination button then I won't get any data.

So how to get the data when we click on each pagination button ?

Thank you.

Start another table by passing a parameter.

$
0
0

When I click on a row of my table, a modal opens showing the data in different tabs. In one of the tabs I want to start another table, passing as a parameter a data of the row selected to be used in the server side query.

Need to help me because I do not know how to do it.

Thank you. Greetings.

Problem with selected rows + stateSave + table.ajax.reload + removed data

$
0
0

This is the problem:
I have a dataTable with some rows loaded with ajax from database, I use the table.ajax.reload function (for reloading data every 10 seconds) and the stateSave (for keep selected rows after every reload of data).
1. I select 3 rows and the selected row counter on the table footer correctly say: "3 rows selected".
2. I remove from database one of the selected rows.
3. The table.ajax.reload function runs and reloads the data on the table and now there are a lower number of rows.
4. Now the remaining visible selected rows is correctly 2 (because one is been removed from database) but the rows counter on the footer of the table count a wrong number! The counter say again "3 rows selected" !!!

How can I solve this problem?

add custom parameters to ajax url after initialization and get new json

$
0
0

Hi
What is the best way to add parameters to the ajax url and get the new filtered json from the server?
What I want is to change the json data when doing an 'onchange' on a select with that selected value
So: I get the value:

type=mySelect[MySelect.selectedIndex].value 
and append it to the ajaxurl:  this.apiUrl += '&type=' + type

that is no problem
When I initialize datatables first my ajaxurl looks like this:
http://127.0.0.1:3000/mockData/searchResult.json?a=1&draw=1&columns%5B0%5D%5Bdata%5D=function&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1536235815080

And when i try to modify/add parameter it looks like this: http://127.0.0.1:3000/mockData/searchResult.json?a=1&type=type-2

So all the original parameters are stripped since they are attached by datatable init.

Am I going down the wrong path or is there a better way to do this?

My initialization looks like this:

table.DataTable( {
            "processing": true,
            "serverSide": true,
            "searching": false,
            "ordering": false,
            "deferRender": true,
            "lengthChange": false,
            "info": false,
            "paging": true,
            'retrieve': true,
            "ajax": {
                url: this.apiUrl
            },
} );
Viewing all 82534 articles
Browse latest View live


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