Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all 1816 articles
Browse latest View live

Images are '404 Not Found' on datatables.net.

$
0
0
I am waiting for the 2.1.6-dev TableTools package... but for now, I am using nightly builds:
<link href="//datatables.net/download/build/nightly/jquery.dataTables.css" rel="stylesheet" type="text/css" /> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script&gt; <script src="//datatables.net/download/build/nightly/jquery.dataTables.js"></script> <link href="//datatables.net/download/build/TableTools.nightly.css" rel="stylesheet" type="text/css" /> <script src="//datatables.net/download/build/TableTools.nightly.js"></script>
In the Firefox console, I am getting this error:

"NetworkError: 404 Not Found - http://datatables.net/download/build/images/sort_asc.png&quot; sort_asc.png
"NetworkError: 404 Not Found - http://datatables.net/download/build/images/sort_both.png&quot; sort_both.png

Can this be fixed, or is there a way I can work around it? My columns are not showing the 'sort' buttons and I need
this functionality.

-Bigsipper

[COMPLETE SOLUTION] - Passing Filtered and/or Paginated Form Fields with Optional Check All Feature

$
0
0
I'm posting this "complete solution" (hopefully it is for the vast majority of you) of how to handle passing form fields that are visible or hidden (due to pagination or filtering) and optionally, having a "check all" checkbox. I spent the last few days culling together various bits to come to this complete solution that met all my needs - hopefully it will save others time in future and possibly help less experienced users understand what is possible with the power of dataTables. Let's get started.

PROBLEM: You need to pass form fields (usually in the form of a checkbox) from rows in your dataTable to another script via a FORM. You need to account for not only form fields that are not visible (say due to pagination or filtering), but also the visible fields as well. A "check all" feature would aid users with large datasets if they wanted to do a "check all", filtering or not.

It's important to understand dataTables removes hidden nodes (aka rows in your dataTable) from the DOM, so simply wrapping a FORM around your dataTable will NOT pass all the checkboxes that are there - it will only pass the visible ones (visible because of the current page in the pagination set you are viewing, or due to filtering of the dataset, or a combination of both).

By including two plugins (one of which is detailed in the dataTables API) (http://datatables.net/plug-ins/api), we can solve these issues.

To include these plugins, you must save the following code to a .js file, or include them BEFORE you initialize the dataTable (e.g.: before the $('yourtable').dataTable() in your script block). If you are including them as a file, they must come AFTER jQuery, and AFTER the dataTables JS script includes. For example:
<script type="text/javascript" src="/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="/js/dataTables.fnGetHiddenNodes.js"></script> <script type="text/javascript" src="/js/dataTables.fnGetFilteredNodes.js"></script>
Notice the two filenames - fnGetHiddenNodes and fnGetFilteredNodes - each one handles different aspects of our problem, and as you might surmise, the fnGetHiddenNodes handles any nodes that are hidden (by pagination), and fnGetFilteredNodes handles any nodes that are filtered (whether they are hidden by pagination or not).

Since fnGetFilteredNodes is not in the API Documentation (the link I provided above), here is the script:
$.fn.dataTableExt.oApi.fnGetFilteredNodes = function ( oSettings ) { var anRows = []; for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ) { var nRow = oSettings.aoData[ oSettings.aiDisplay[i] ].nTr; anRows.push( nRow ); } return anRows; }; copy the above into a new file and save it as dataTables.fnGetFilteredNodes.js and follow the inclusion instructions previously mentioned.

fnGetHiddenNodes is available in the API documentation, but here it is anyway for convenience:
$.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( oSettings ) { /* Note the use of a DataTables 'private' function thought the 'oApi' object */ var anNodes = this.oApi._fnGetTrNodes( oSettings ); var anDisplay = $('tbody tr', oSettings.nTable); /* Remove nodes which are being displayed */ for ( var i=0 ; i<anDisplay.length ; i++ ) { var iIndex = jQuery.inArray( anDisplay[i], anNodes ); if ( iIndex != -1 ) { anNodes.splice( iIndex, 1 ); } } /* Fire back the array to the caller */ return anNodes; };
Now, in order to implement the "check all" feature, you'll need an input in your dataTable output - there's a million different ways to do this, but here's the code I use:
<input name="Custodians" type="checkbox" value="All" class="checkall">
This input (which you can put in the TH section of your TABLE) will be what the user will click on to select all the checkboxes in the data set (visible or not, filtered or not).

Here's the script that initializes your dataTable, and also implements the check all feature, and the calls to ensure the checked fields (whether hidden, filtered, or not) are passed to your form:
$(document).ready(function () { oTable = $('#LHQResponses').dataTable(); } ); $('form[name=yourformsnameattribute]').submit(function(){ //replace 'yourformsnameattribute' with the name of your form $(oTable.fnGetHiddenNodes()).find('input:checked').appendTo(this); //this is what passes any hidden nodes to your form when a user clicks SUBMIT on your FORM } ); $('.checkall').click( function() { //this is the function that will mark all your checkboxes when the input with the .checkall class is clicked $('input', oTable.fnGetFilteredNodes()).attr('checked',this.checked); //note it's calling fnGetFilteredNodes() - this is so it will mark all nodes whether they are filtered or not } );
Assuming your FORM is wrapped around your TABLE in your HTML output, this should work with no problems. Please note the fields are submitted when a user clicks on your FORM's SUBMIT button, after they have clicked on at least one checkbox in your TABLE output or the checkbox to select all checkboxes.

Huge thanks to everyone (especially Allan) who contributed portions of the above solution, and I hope posting it here all together helps others and saves time!

Datatable conflict with Dojo

$
0
0
Hi,

I notice a very annoying conflict between datatable and dojo.js

Trying this simple example :
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"></script&gt; <script type="text/javascript" src="jquery-1.10.2.min.js"></script> <script type="text/javascript" src="jquery-ui-1.10.3.min.js"></script> <script type="text/javascript" src="jquery.dataTables-1.9.4.min.js"></script> <script> $(document).ready(function() { $("#mytable").dataTable(); }); </script> </head> <body> <table id="mytable"> <thead> <tr><th>Name</th></tr> </thead> <tbody> <tr><td>Test</td></tr> </tbody> </table> </body> </html>
Give me the js error : Uncaught TypeError: Object [object Object] has no method 'dataTable'

p.s : i'm using the Alfresco Share 4.2.0 product that includes dojo.js so i don't have the ability to remove this dependency.

Anybody knows how can i workaround on this ?

Thank you !

Clear saved state by clearing local storage

$
0
0
Hi

My application uses tables with a whole bunch of columns. I'm using the fabulous ColVis plugin to hide and show the columns the user wants. Thanks to fnStateSave, I can very easily keep all filters and columns present after a page reload.

The problem is that if there's a filter present in one of the columns (I've got input boxes below each column) and that column is hidden, it's confusing for the user. The user sees a filtered table, but cannot see which column has been filtered.

My question is: I would like to implement a global table reset button, that clears the saved state of the current table only: filters, columns... the whole shabang. Ideally the button would be displayed in the same manner as the TableTools and ColVis buttons.

How would I go about implementing such a feature?

"bStateSave": true, "fnStateSave": function (oSettings, oData) { localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) ); }, "fnStateLoad": function (oSettings) { return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) ); }, "fnStateLoadParams": function (oSettings, oData) { $(oData.aoSearchCols).each(function(index,value) { if(value.sSearch != '') { $("input.search_init[data-colno='" + index + "']").val(value.sSearch); } }); }
Thanks in advance for your answer. And thank you for your great software! My client LOVES it!

Custom message in sInfo using Scroller

$
0
0

I am trying to put a custom message in sInfo as below: <span class="lvllbl"></span> "sInfo": 'There are a total of TOTAL <span class="lvllbl"></span>(s).',

But the Scroller doesn't seem to put the message. If we remove the Scroller it would work just fine and the message is displayed. I am using Datatable 1.9.4 and Scroller 1.1.0. But this even doesn't work on the latest version.

Here is the code:

$(document).ready(function() {
                var lvllbl;
                var table = $('#hierlvl2list').dataTable( {
                    "sDom": '<"H"Tf<"clear">><"top"i>t<"F">rS',
                    "bJQueryUI": true,
                    "bServerSide": true,
                    "sScrollX": "100%",
                    "sScrollY": "400px",
                    "bScrollCollapse": true,
                    "bAutoWidth": false,
                    "bProcessing": true,
                    "bDeferRender": true,
                    "sAjaxSource": "${pageContext.request.contextPath}/admin/hierarchy/hier_lvl2_list.html?action=listlvlitems&orgid=${param.orgid}",
                    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
                        oSettings.jqXHR = $.ajax( {
                            "url": sSource,
                            "data": aoData,
                            "type": "POST",
                            "dataType": 'json',
                            "success": function(data) {
                                var hasError = fnCheckError(data);
                                if(!hasError) {
                                    lvllbl = data.lvllbl;
                                    fnCallback(data);
                                }
                            }
                        });
                    },
                    "aoColumns": [
                        { "sTitle":"Level Title", "mData": "lvlTitle", "sClass": 'col_header' }
                    ],
                    "oLanguage": {
                        "sInfo": 'There are a total of _TOTAL_ <span class="lvllbl"></span>(s).',
                        "sInfoEmpty": 'There are a total of _TOTAL_ <span class="lvllbl"></span>(s).',
                        "sEmptyTable": 'There are no <span class="lvllbl"></span>(s) to display',
                        "sZeroRecords": 'There are no matching <span class="lvllbl"></span>(s) to display',
                        "sProcessing": 'Please wait - loading <span class="lvllbl"></span> (s) ...'
                    },
                    "fnDrawCallback": function(oSettings) {
                        if(lvllbl) {
                            $('span.lvllbl').html(lvllbl);
                        }
                    },
                    "fnHeaderCallback": function( nHead, aData, iStart, iEnd, aiDisplay ) {
                        nHead.getElementsByTagName('th')[0].innerHTML = '<div class="DataTables_sort_wrapper">'+lvllbl+'<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span></div>';
                    },

DataTables 1.10 serverside sp.class.php

Multiple table with aoColumnDefs

$
0
0
Hi everyone,

I've got two tables on the same page which i initialize in the same times ($(document).ready).
I use these with tabbable (bootstrap 2.3.1) to switch from one to the other.
The first one haven't any problem, it is correctly initialized. But the second not. The column width isn't right.

Can you help me please?
Thanks

accent insensitive filter

$
0
0
hi,

is it possible to do filter that is accent insensitive ?

Thanks

Sort without accents

$
0
0
Hello There,

Im having problem sorting word that have accent. i found a post here that a guy named rbraga found a solution.
The solution was that the code snippet that he wrote remove all accent before sorting. but i can't understand how to use the code, in fact i thing the code is incomplete:

at jquery.dataTables.js

[code]
function removeAccents(strAccents){
strAccents = strAccents.split('');
strAccentsOut = new Array();
strAccentsLen = strAccents.length;
var accents = '

I would really love if someone could help me on this, please.


Ivan Lopes

legacy 1.9 - need button on row to invoke editor in edit mod

$
0
0

sorry this is probably a question answered a million times before in the past, but I can now only find 1.10 discussions. So: need to have an "Edit" button on each row, that brings up Editor in edit mode for that row? Thx in advance.

What is causing the Item Index # (# items in datasource) to show in Chrome or IE 10 or Higher

$
0
0

I'm new to the Datatables plug-in and I'm experiencing a very frustrating occurance/issue and I think it's related to the Datatables plug-in. The Datatables plug-in is an excellent tool and everything is working great in my project, except when I test my pages in Google Chrome or IE 10 or higher; I get a mysterious row above my datatable showing what appears to be the item index number showing in a separate row. This is displayed as a horizontal listing. .

For instance, if I have 12 items in my datasource. It shows the datatables formatted table correctly, but on top of the table it shows a row with the following:

1 2 3 4 5 6 7 8 9 10 11 12

The numbers are displayed as text only.Usually I would see each # listed as a link, sort of like an html bookmark.

Can anyone help me: 1) identify what this feature is? (Note, I called it (item index number) listed above...I don't know if I'm calling it the right thing (I don't see this in source view of the rendered page)) 2) How I can turn this off for IE 10 or higher and Chrome.

Thanks in advance

Jeff

Re-initialize dataTable from fnServerData

$
0
0

Datatable is being initialized with 2 ajax calls: table structure (columns) and table data. Structure data is being cached.

Case: User removes last records from table Table being initialized (reDrawn) Re-cache table structure

    // 1) Get table structure
    // 2) render table 
    // 3) initialize dataTable
// If there are any records, structure is cached in localStorage()
function setupTable() {
    function getStructure() {

      if (response.iTotalRecords > 0) 
        localStorage.setItem(structureName, JSON.stringify(response));

    }
    oTable.renderTable(); // render table structure in document
    oTable.initTable();
}

function initTable() {  
    function fnServerData() {
      // If has cached structure but doesn't have records
              // -> setup dataTable with fresh structure
          if (iTotalRecords === 0 && hasCachedStructure()) {

      // step 1) Remove old cached structure
      localStorage.removeItem(structureName);

       // step 2) Destroy table before initializing it again
       oTable.fnDestroy();

       // step 3) Get new structure and initialize datatable with new structure
       setupTable();

      }
    } 
}

The issue is that dataTable controls (column, pagination, footer info) is not being destroyed. How can I do clean table destruction and setup table from start?

Thank you for your time and any guidance.

reload data after clicking button

$
0
0
I load data by default like this

$('.datatable').dataTable({ "sPaginationType": "bs_full", "bProcessing" : true, "sAjaxSource" : "loadusers.html", "sAjaxDataProp" : "test" });
My table on html page looks like this
<table class="datatable table table-striped table-bordered" id="usertable"> <thead> <th>Name</th> <th>Surname</th> <th>Username</th> </thead> <tbody> </tbody> </table>

Server answer looks like this
return "{ \"test\": [ " + "[ \"name1\", \"surname1\", \"username1\"]," + "[ \"name2\", \"surname2\", \"username3\"]," + "[ \"name2\", \"surname2\", \"username3\"]" + "] }";

But how to load data by clicking button on the page? For example by clicking button
<button id="button1" class="btn btn-primary">Clicker</button>

Jquery version compatibility with DataTables 1.9.4

$
0
0
Hi all, we are using jQuery 1.7.1, is it compatible with the 1.9.4 release of DataTables?

same mRender function for multiple columns

$
0
0
I'm using mRender to provide a rendering function for two columns in a DataTable. However, I can't use the same aoColumnDefs entry for both columns, because they access different columns of the data source, and mData only allows me to specify one column index.

Do I really need to repeat the mRender declaration for each column, even when they use the same renderer function, like so?
$('#vis').dataTable({ 'aoColumnDefs': [ { 'mRender': rendererFunction, 'mData': 3, 'aTargets': [ 3 ] }, { 'mRender': rendererFunction, 'mData': 4, 'aTargets': [ 4 ] }, ]});

localStorage for state saving and updates in 1.9

Exclude expression onglobal search

$
0
0

Hello, I created an advanced search with all the columns of my database, I have also the first search field called Global Search. I would like to know how can I exclude one expression from the search. E.g. Considering I have columns State and City, I want to load all users from NY State expect the ones from NY City. So, how do I to exclude NY city from the search and search results?

My example: http://goutam.webigniter.ca/datatable.html

Datatabls only showing first 10 rows of 200 row table

$
0
0

Hi I've had my set up working for ages but now it only wants to show the first 10 rows and I can't see what's changed to make it do this. The data is pulled from a database via ajax and I can see all the rows in the data source

My initialisation is:

oTable = $('.datatable').dataTable({
        "bServerSide": false,
        "bDeferRender": false,
        "bProcessing": false,
        "sAjaxSource": "/siteuser/datatable",
        "sDom": "<'row'<'col-xs-6'l><'col-xs-6'f>r>t<'row'<'col-xs-6'i><'col-xs-6'p>>",
        "sPaginationType": "bs_full",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page"
        },
        "iDisplayLength": 10,
        "aaSorting": [
            [1, "asc" ]
        ],
        "aoColumns": [
            {'bSortable': true, 'sClass': 'text-center'}, //id
            {'bSortable': true}, //date
            {'bSortable': true}, //category
            {'bSortable': true, 'sClass': 'text-center'}, //valid+member
            {'bSortable': true, 'sClass': 'text-center'}, //valid+member
            {'bSortable': true, 'sClass': 'text-center'}, //valid+member
            {'bSortable': true, 'sClass': 'text-center'}, //disabled
            {'bSortable': false, 'sClass': 'text-center'} //actions
        ]
    });

The status only states showing 10 rows from 10

I've run the page through the debug tool and here's a link: http://debug.datatables.net/upaqej

I can't see any errors in the console so not sure what's creating this problem

How to use datatable with a complex query?

$
0
0

I have the following query which I converted into a MySQL View, however, when using the View in datatables and passing some where filters, it takes forever for a query to run. When the following query is run on its own it runs very fast.

My question then is, how can I use the following query in server side processing with datatables? Any help would be much appreciated.

    SELECT 
        od.id AS id,
        od.userid AS orderuserid,
        cu.id AS customerid,
        us.id AS userid,
        concat(us.firstname, ' ', us.lastname) AS username,
        cu.customername AS customername,
        od.productid AS productid,
        od.ordernumber AS ordernumber,
        sum(od.quantity) AS qty_sum,
        od.orderdate AS orderdate,
        count(od.ordernumber) AS sub_sum
    FROM
        ((table_orderdetails od
        join table_customers cu)
        join table_users us)
    WHERE
        (od.userid = us.id) and cu.id = { variable to be passed}
        and date(orderdate) = '{variable to be passed}'
    GROUP BY cu.customername , od.orderdate , od.userid , od.productid , od.quantity , us.username , od.productid , od.ordernumber
    ORDER BY cu.customername , od.orderdate , od.userid , od.productid , od.quantity

How to pass a PHP form variable to server processing for use in WHERE clause?

$
0
0

I have a form in my application where you select a "customer" and a "startdate" and "enddate".

When the user clicks on "submit", I want to pass these 3 POST variables through to datatables to be used in a WHERE clause to filter the results.

I've tried a bunch of things with no success. Using Firefox I can see the variable "formCustomer" in the "params".

Here's my code but how do I read the "formCustomer" variable in the page "scripts/server_processing_stock.php"?

    <script type="text/javascript" language="javascript" class="init">

        $.extend( $.fn.dataTable.defaults, {
            responsive: true
        } );        
        
        $(document).ready(function() {
            $('#stock_report').dataTable( {
                "language": { "infoFiltered": ""},          
                "order": [[ 1, "desc" ]],
                "processing": true,
                "serverSide": true,
                "ajax": {
                        "type": 'POST',
                        "url": 'scripts/server_processing_stock.php',
                        "data": {
                            formCustomer: '<?php echo $_POST["sel_customer"] ?>',
                        }
                    }

            } );
        } );

    </script>   
Viewing all 1816 articles
Browse latest View live