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

Dynamic button to hide/show rows

$
0
0

Hello,

I am trying to create a button collection to show or hide the rows that match that button content.
Using the datable example here), I want to create a button "Office Selection" that is a collection of the buttons "Tokyo", "London", "San Francisco", and so on.
Lets say that all the buttons but "London" are clicked by default (like the button "salary" in the example).
In that case the table will show all the data without the rows with London in the column office. If i click the button "London", it will show the content again.

So, what I want is something like the colvis button but using the data of a specific column.

Can anyone please help me?


Added a second table to a page, child rows stopped working.

$
0
0

I have a page, Demo1 - Copy.html, that contains one table and makes use of child rows. It's working fine, AFAIK.

In Demo.html, I added a second table, which uses a second data source. When I made that change, child rows quit working. I can see at least part of the problem -- for example, I'm sure that #example at line 141 needs to be change-- but I don't know how to fix it. Anyone know right off how to fix this?

Numeric Sorting How To

$
0
0

I am using the 1.10 version of data tables over the DOM. For some reason the datatable is not sorting the dollar sign amounts in the columns correctly. What are some workarounds to making this work?

unable to implement Individual column searching (text inputs)

$
0
0

I am trying to implement the search but unable to do it.

following is the error:

jquery.dataTables.min.js:122 Uncaught TypeError: Cannot read property 'nodeName' of null
at jquery.dataTables.min.js:122
at $a (jquery.dataTables.min.js:109)
at r.<anonymous> (jquery.dataTables.min.js:121)
at r.iterator (jquery.dataTables.min.js:99)
at r.<anonymous> (jquery.dataTables.min.js:121)
at r.columns (jquery.dataTables.min.js:102)
at r.<anonymous> (jquery.dataTables.min.js:126)
at r.column (jquery.dataTables.min.js:102)
at r.<anonymous> (dataTables.responsive.min.js:18)
at r.filter (<anonymous>)

search on special characters

$
0
0

we need to search on special characters with rang filter.
like: salary type columns "$ 150,000"

Printing Datatable with Many Columns

$
0
0

I am trying to print a datatable with many columns. The whole table is shown on the screen but when I click print, the columns keep getting stretched. As a result some columns get clipped from the printed document. I have tried using the customize function to set the td width but to no effect. Can anyone help me out?

This is what I tried following datatables documentation:

customize: function ( win ) {
$(win.document.body).find('table').addClass('display').css('font-size', '5px');
$(win.document.body).find('table').css('table-layout','auto');
$(win.document.body).find('th').css('width','10%');
$(win.document.body).find('td').css('width','10%');
}

rowGroup - Display multiple column values in Group Header.

$
0
0

Hello,
i got a datatable with rowGroup, using following code:

'rowGroup': {
                        startRender: function (rows,group ) {
                            return group;
                        },
                        dataSrc: [1],
                    },

This produces a Group like:

Name


Street | ID | Order
Street | ID | Order
Street | ID | Order
Street | ID | Order

And i want a group which looks like:

Name - Street - ID


Order
Order
Order
Order

How can i access the Data and how to modify the group header?

Best Regards,
DTDev

ColReorder & Individual Column Filtering Positioned In Header

$
0
0

I know this has been asked before but I cant find a working solution at the moment. I am using a combination of ColReorder, horizontal scrolling and individual column filtering. I cant make the col reorder function work from the top THEAD row and the filtering work from the second THEAD row. Both functions only work if I leave bSortCellsTopas false. However, I need the col reordering to be in the first THEAD row as that is better from a usability point of view.

How I can target the second row in THEAD with this function?

            table.columns().every( function () {
                var that = this;
                $( 'input', this.header() ).on( 'keyup change', function () {
                    if(that.search() !== this.value){
                        that
                        .search( this.value )
                        .draw();
                    }
                });
            });

Any help would be greatly appreciated.

Thanks

Chris


Common export buttons for multiple tables on same page

$
0
0

Hi
I have a page with multiple datatables and I want common export buttons for them..
I mean, when I click the common pdf / excel button the data from all tables should be shown as pdf OR excel respectively...

Any example of how to achieve it would be really appriciated.

Thanking in anticipation.

multiple headers on same table??

$
0
0

I Want to create complex table structure for a report as below

Seller Details          Buyer Details           Broker Details
Company Name            Company Name            Company Name
Address         Address         Address
GST NO          GST NO          GST NO
Phone No            Phone No            Phone No

        Invoice Details
Invoice No
Invoice Date
Invoice Rate
Invoice Weight
Bags
Lorry No

        Receipt Details
Sauda No
Sauda Rate
Received Weight
Bags
Received Date

is it possible to do so ... and examples woudl be really appriciated ....

Change the data while changing table

$
0
0

Hi in my current projet i have a feature that allow the user to switch rows from one tab to another, so far it's working as intended.

What i want to do now is to check the .data() and do something depending on what's in the first column, but so far when i use.data, i get a long string of the whole TH row and i can't see to be able to split it to get the first value.

I use this piece of code to swap lines from one tab to the next :

var addRow = rulesTable.row($row);
caractTable.row.add(addRow.data()).draw();
addRow.remove().draw();
value = addRow.data();

Anyone who could help me achieve this ?

Using datatables in server side.

$
0
0

I'm a beginner to web development, I'm trying to display a table in a webpage file(say: "index.php"), it'll be generated on my server side PHP script by querying my database(say:"backend.php"). I'm using AJAX request(using jquery in "request.js") to fetch the table to "index.php" from "backend.php". I currently have my table styling inline in "backend.php" and using echo command in "backend.php" to display the table through response in "request.js".
1.Where should I include my script src and javascript code?
2.Please guide me to use DataTables in a proper way to sort and search tables.

A tiny example code will be very helpful.

how to search only visible columns

$
0
0

when i am searching in datatable it is searching in hidden columns also. how to search only visible columns only

Data tables in Thymeleaf

$
0
0

Hi there, I was wondering how well data tables work when using them in conjunction with the Thymeleaf templating engine. All works well in the code below until I try to reference the mapping.address key in the java properties file using the Thymeleaf syntax th:text and then I get a "Bad JSON array in data-wb-tables attribute" error. Any help you could provide would be appreciated.

<

table class="wb-tables data-wb-tables="{'language': {'emptyTable': th:text='#{mapping.address}'}}">

Make the returned JSON into a global array.

$
0
0

I am using the following to bring back some JSON data.

I want to use

var selectedArray =[] // global array.

How do I assign the returned data to selectedArray

       ajax :       {
                            'url' :  'http://www.xxxx.com/php/xxxx.php',
                            "type": "POST",
                                  "data": {
                                                'selectedInvoiceID': selectedInvoiceID
                                              }

                          },

Cheers

Steve Warby


DataTables Ignored in Some IE11 Instances

$
0
0

I have an application that I added datatables to. It works brilliantly... on most machines. However, I've found that on certain people's machines, it is failing to render ANY HTML for the datatable. It simply acts like the datatables statement doesn't exist.

Troubleshooting

  1. Most users using IE11 can bring up the data table perfectly fine.
    (note: please, no beating me up over IE. It's a corporate environment and it's not my choice)
  2. This only happens in the IE11 browser on a few particular machines.
  3. Other browsers like Chrome, Edge, etc. on the same machines work fine.
  4. For non-working browsers, they don't work against any of the servers hosting the site.
  5. I've disabled all browser extensions not on a working machine.
  6. No errors are generated in the console in F12 developer tools.
  7. I've thrown alert statements in the same <script> section and it fires.
  8. I've put an alert statement in the same document.ready section and it fires as well.
  9. No alerts in the datatables AJAX success or error sections fire.
  10. I've stepped through the code and the datatables statement is hit.

Packages Used

  • jQuery v1.10.2
  • jquery.datatables v1.10.15

Code Attached

  • index.cshtm

Using vh units with scrollY

$
0
0

Hello,

I would like to use vh units with scrollY in order for my datatable to fill up the screen regardless of the user's screen size. However, when I try this, I get a strange result upon the very first load (I am using server-side processing, and the data immediately loads upon page load). Specifically, the data only fills up to about halfway down the table, and then no more rows are loaded. But I know for a fact that hundreds of rows should be loading, and therefore the visible table should be completely filled with data (it works properly when I use px units for scrollY). But then, upon subsequent data loads, the data populates the table fully, as expected.

Here is my datatable code:

    var dtRecords = $('#tblRecords')
        .on('error.dt', function (e, settings, techNote, message) {
            console.log('An error.dt event has occurred.');
            try {
                throw (new Error(message));
            }
            catch (err) {
                HandleError(true, 'From error.dt: ' + err.stack);
            }
            finally {
                return false;
            }
        })
        .DataTable({
            dom: 'BtSir',
            serverSide: true,
            ajax: {
                url: "MktSegIndService1.asmx/LoadRecords",
                type: "POST",
                dataType: "json",
                data: function(d){
                    d.isTextSearch = isTextSearch;
                },
                error: function (xhr, status, error) {
                    HandleError(false, 'From DataTables AJAX error section: ' + error);
                }
            },
            columns: [
                { data: "ORIGINAL", className: "colOrig" },
                { data: "CHILD" },
                { data: "MarketSegment", className: "mktSeg" },
                { data: "SIC", className: "sic" },
                { data: "PARENT" },
                { data: "ULTIMATE" },
                { data: "State" },
                { data: "Country" },
            ],
            keys: {
                blurable: false
            },
            buttons: {
                buttons: [
                    {
                        text: 'Copy',
                        key: {
                            key: 'c',
                            ctrlKey: true
                        },
                        action: function (e, dt, node, config) {
                            console.log('copy action!');
                            try{
                                var copiedCell = dt.cell({ row: focusedRowIdx, column: focusedColIdx });
                                copiedCellData = copiedCell.data();
                            }
                            catch (err){
                                HandleError(true, "From Copy action: " + err.stack);
                            }
                        }
                    },
                    {
                        text: 'Paste',
                        key: {
                            key: 'v',
                            ctrlKey: true
                        },
                        action: function (e, dt, node, config) {
                            console.log('paste action!');
                            try{
                                var field = dt.column(focusedColIdx).dataSrc();
                                if (field === "MarketSegment" || field === "SIC") {
                                    alert("CopiedCellData = " + copiedCellData);
                                    editorObj
                                        .edit(focusedRowIdx, false)
                                        .set(field, copiedCellData)
                                        .submit();
                                } else return false;
                            } catch (err) {
                                HandleError(true, "From Paste action: " + err.stack);
                            }
                        }
                    }
                ]
            },
            scroller: {
                displayBuffer: 15
                ,
                loadingIndicator: true
            },
            //deferRender: true, // Don't need this with server-side processing
            colReorder: {
                realtime: false
            },
            scrollX: true,
            scrollY: "80vh",
            scrollCollapse: true,
            searching: false,
            ordering: false,
            processing: false,
            info: false,
            rowId: "Row",
            select: true
        });

Need the proper syntax to set a value of a field.

$
0
0

Need the proper syntax to set a value of a field by calculated the values of 2 0tger fields in my server side PHP.

Here is what I have tried.

        Field::inst('xxxx.Fld1),
        Field::inst('xxxx.Fld2),

        Field::inst('xxxx.Fld3)
               ->setValue( Field:: Fld1 * Field:: Fld2 )


Rendered input radio undefined when selected

$
0
0

This is a tough one ...at least for me. I have a simple input radio button that is available in every row which is created in a column render. The problem is when the radio is selected it does not have the 'checked' attribute associated to it, however if i pre-set the radio value as 'checked' it the column render it does have the 'checked' attribute associated to it. I was able to test this with a button that iterates over the table rows and checks the value of each button. I hope someone can help me out with this.

This does not work...

         {sortable: false,
                "render": function ( data, type, full, meta ) {
                           return '<input type="radio" id="plantManagerApprovalRadio_'+ table.data().count() +'" >'
               }// End - "render": function ( data, type, full, meta )
            },

This does work...

         {sortable: false,
                "render": function ( data, type, full, meta ) {
                           return '<input type="radio" id="plantManagerApprovalRadio_'+ table.data().count() +'" checked >'
               }// End - "render": function ( data, type, full, meta )
            },

Full script


<script type="text/javascript" src="/js/jquery-current.min.js"></script> <script type="text/javascript" src="/jquery-ui-1.12.0/jquery-ui.min.js"></script> <script type="text/javascript" src="/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="/js/dataTables.fixedColumns.min.js"></script> <script type="text/javascript" src="/js/dataTables.buttons.min.js"></script> <script type="text/javascript" src="/js/dataTables.select.min.js"></script> <script type="text/javascript" src="/DataTables_Editor/js/dataTables.editor.min.js"></script> <script type="text/javascript" src="/js/dataTables.rowGroup.min.js"></script> <script type="text/javascript"> var editor; //global for the submit and return data rendering var table; // global for the data table //**************************************************************************** //** $(document).ready(function() //**************************************************************************** $(document).ready(function() { editor = new $.fn.dataTable.Editor( { ajax: "ssp_xxxxxxx.php", table: "#approvalTable", fields: [{label: "Percent of Increase", name: "xxxPER", attr: {maxlength:4, style:"height:20px; width:50px",} }, {label: "Review Score", name: "xxxWREV", attr: {maxlength:3, style:"height:20px; width:35px",} }, {label: "Effective Date", name: "xxxEDT", attr: {style:"height:20px; width:80px",}, type: "datetime" }, {label: "Comments", name: "xxxCOM", attr: {maxlength:500}, type: "textarea" }, ] } ); // Activate an inline edit on click of a table cell $('#approvalTable').on( 'click', 'tbody td:not(:first-child)', function (e) { editor.inline( this, { onBlur: 'submit' } ); } ); table = $('#approvalTable').DataTable( { lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], fixedColumns: { leftColumns: 6, rightColumns: 5 }, scrollX: true, ajax: "ssp_xxxxxxxx.php", type: 'POST', order: [[2, 'asc']], columns: [ // *** Fixed left columns { data: "numeric_month", "visible": false }, { data: null, defaultContent: '', className: 'select-checkbox', orderable: false }, { data: "xxxLOCD"}, { data: "month_name"}, { data: "xxxEMPN" }, { data: "xxxNAME" }, // *** Scrollable columns { data: "xxxMGNA" }, { data: "xxxMGN2" }, { data: "xxxMGN3" }, { data: "xxxMGN4" }, { data: "xxxMGN5" }, { data: "xxxRWPER" }, { data: "xxxWREV" }, { data: "xxxDNAM" }, { data: "xxxTITL" }, { data: "xxxJBGD" }, { data: "xxxYREG" }, { data: "xxxWNEW" }, { data: "xxxWAMT" }, { data: "xxxDLIN" }, { data: "xxxSEDT" }, { data: "xxxMIN" }, { data: "xxxMID" }, { data: "xxxMAX" }, { data: "xxxOCOM" }, { data: "xxxNCOM" }, // *** Fixed Right columns // ** Comments Button {sortable: false, "render": function ( data, type, full, meta ) { if(full.xxxWCOM.trim() == ""){ return '<button class="gray button" onclick="openCommentDialog('+ full.xxxEMPN +', \''+ full.xxxNAME +'\' )">Comments</button>'; }else{ return '<button class="blue button" onclick="openCommentDialog('+ full.xxxEMPN +', \''+ full.xxxNAME +'\' )">Comments</button>'; } }// End - "render": function ( data, type, full, meta ) }, // ** Plant Manager Approval Button {sortable: false, "render": function ( data, type, full, meta ) { return '<input type="radio" id="plantManagerApprovalRadio_'+ table.data().count() +'" >' }// End - "render": function ( data, type, full, meta ) }, ], columnDefs: [ {"targets": [ 0 ], "orderData": [ 0, 2 ] }, {"targets": [ 2 ], "orderData": [ 0, 2 ] }, {"className": 'dt-center', "targets": [ 25, 26, 27, 28, 29, 28] }, {"targets": [25, 26, 27, 28, 29,28], "orderable": false }, { 'targets': [4], 'createdCell': function (td, cellData, rowData, row, col) { $(td).attr('id', 'employeeID_' + table.data().count()); } } ], select: { style: 'os', selector: 'td:first-child' }, buttons: [ // { extend: "create", editor: editor }, { extend: "edit", editor: editor }, // { extend: "remove", editor: editor } ] } ); } );//END $(document).ready(function() //************************************************************************ function approveIncrease(){ var rows = table.data().count(); for (i = 1; i < rows; i++) { var isChecked = $("#plantManagerApprovalRadio_"+ i).attr('checked'); alert(isChecked); }//* End - for (i = 1; i < row; i++) }//*End - approveIncrease </script>

Set background color of column

$
0
0

I would like to change the background color of columns that are editable, but when I do this using the classname, it also changes the background color of that column's header, which I don't want. Is there a way to highlight the td cells but not the th? This is how I currently have it:

DT column
{ "data": "UserFlag", "className": "table-cell-edit" }

CSS
.table-cell-edit{
    background-color: lightgoldenrodyellow;
}
Viewing all 81971 articles
Browse latest View live