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

Correct use of .dataTable().clear().draw();

$
0
0

My apologies if this has been answered, I'm not seeing it in the forums.

In an MVC Web API 2 site, I've created a simple form which queries the web service, to get three distinctly different result sets of data. In jQuery, I'm hiding or showing the div & table based on logic provided by the 3 field request form. The web service provides the data, however I'm having issues clearing the data from the table if the report is changed.

My intended result, is that when a report is changed via the dropdownlist, and the user clicks the submit button, the dataTable is cleared of all data, and the appropriate table is filled with the new data based on the "_type" of report.

In the OnSubmit() method tied to the HTML submit button, I'm attempting to clear the dataTable via $("#MyTable").dataTable().clear().draw();

What appears to be happening, is that the jquery.dataTable.js file experiences an invalid argument @ line 2025, causing the removal of the table and div.

I believe that code is meant to create an empty row in the table.

If I do not "clear" and "draw" the datatable by removing the "ClearTables()" method call, I can see the expected results in the datatable, however I receive an error for "datatables.net/tn/3" when I attempt to get the data again (additional criteria from the form), or a tn/4 when changing the type.

My script: (Generalized....may contain type-o's):

var _type = null;

function HideTables(){
$('#myTable1').hide();
$('#myTable2').hide();
}

function ClearTables(){
$('#myTable1').dataTable().clear().draw();
$('#myTable2').dataTable().clear().draw();
}

function OnSubmit(){
HideTables();
ClearTables();

 if (!($('#ddlReportType :selected').val() == "")){
      _type = $('#ddlReportType :selected').val();
 } 

 // using a promise accessing data from another .js file which provides the json data as "results"
 $.when(GetData()){
      .then(function(results){

           if (_type == "Table1Data"){
                $('#divTable1').show();
                $('#myTable1').show();
                $('#myTable1').dataTable({
                     data: results,
                     "aoColumns" :  [
                          { "mData" : 'col1' },
                          { "mData" : 'col2' },
                          { "mData" : 'col3' }
                      ]
                 });
            } // END: if

           else {
                $('#divTable2').show();
                $('#myTable2').show();
                $('#myTable2').dataTable({
                     data: results,
                     "aoColumns" :  [
                          { "mData" : 'col1' },
                          { "mData" : 'col2' },
                          { "mData" : 'col3' },
                          { "mData" : 'col4' },
                          { "mData" : 'col5' }
                      ]
                 });

           } // END: else

      }); // END: .then

} // END: OnSubmit()


Editor - standalone - inline.How to get access to all editable fields and not only to the edited one

$
0
0

I am using inline edit with a standalone editor. There are 6 fields that can be edited. Before submitting any changes to the server I will perform field validation on the client side. This sounds easier than it happens, because in the preSubmit only the last edited field will be available. I was looking for some kind of API function to get this field name. I could not find anyone. So maybe I have overlooked something. In the meantime, I resolved this with the following approach:

/*  Validate fields before submitting to the server. */
editor.on(`preSubmit`, function(e, data, action)
{
    /*
        Inline edit will not give access to all the editable fields, but only to the
        edited one. So we need to check which field has been edited before we can attempt
        to do any validation.
    */

    field = e.currentTarget.s.includeFields[0];
    fieldVal = eval(`this.field("`+field+`").val()`);

    switch (field)
    {
        case `field1`:
            if ( ! fieldVal)
            {
                field.error(`message`);
            } 
            break;

        case `field2`:
            if ( ! fieldVal)
            {
                field.error(`field`);
            }
            break;

        .........
        .........
    }

    if (this.inError())
    {
        return false;
    }
});

I would like to know, however, if there is not another way to achieve this, for example with an already existing API function.

Cannot use Row Grouping extension for Angular 2

$
0
0

We've got an Angular Component, and we need to implement the RowGrouping Extension (already installed via NPM); but for some reason, when running our app in the browser, The console throws this error:

GET http://localhost:1234/datatables.net-rowgroup 404 (Not Found)

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:1234/datatables.net-rowgroup
Error: XHR error (404 Not Found) loading http://localhost:1234/datatables.net-rowgroup

If the DT buttons are working fine, why the Row Grouping extension is not?. I do thank you all in advance:

In the package.json file, you can check that the RowGrouping Extension is already installed, still, nothing availed.. :neutral:

(datatable-component.ts)
import { Component, OnInit, Input, ViewEncapsulation, ViewChild, ElementRef } from '@angular/core';
import * as $ from 'jquery';
import 'datatables.net';
import 'datatables.net-buttons';
import 'datatables.net-buttons.html5';
// import 'datatables.net-rowgroup'; // HERE IS FAILING
import 'datetime-moment';
import 'dataTables.bootstrap.min';

@Component({
selector: 'data-table',
templateUrl: './data-table.component.html',
styleUrls: ['./css/dataTables.bootstrap.min.css', './data-table.component.css', './css/buttons.dataTables.min.css'],
encapsulation: ViewEncapsulation.None
})
export class DataTableComponent implements OnInit {
@ViewChild('tableElement') tableElement: ElementRef;

currentDatatable: any = null;

constructor() {
    $.fn.dataTable.moment('MMM DD YYYY');
}

ngOnInit() {

}

setConfig(config: any) {
    if (this.currentDatatable){
        this.currentDatatable.destroy();
    }
    config.buttons = config.buttons || [{
        text: 'Download to Excel',
        extend: 'csv',
        className: 'button-to-link'
    }],
    config.oLanguage = { "sSearch": '<i class="fa fa-search" aria-hidden="true"></i>', "sLengthMenu": "Show _MENU_" };
    config.dom = '<"top"lf>t<"bottom"pi>B'; /* Ubicacion de diversos controles de datatable: https://datatables.net/examples/basic_init/dom.html */
    this.currentDatatable = $(this.tableElement.nativeElement).DataTable(config);
}

getDataFromRow(row: any): Object {
    if ($(this.tableElement.nativeElement).find('td').length == 0) {
        return null;
    } 
    var table = $(this.tableElement.nativeElement).DataTable();
    let result = table.row(row).data();
    return result;
}

}

(package.json)
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/common": "~4.0.0",
"@angular/compiler": "~4.0.0",
"@angular/core": "~4.0.0",
"@angular/forms": "~4.0.0",
"@angular/http": "~4.0.0",
"@angular/platform-browser": "~4.0.0",
"@angular/platform-browser-dynamic": "~4.0.0",
"@angular/router": "~4.0.0",
"angular-in-memory-web-api": "~0.3.0",
"angular2-draggable": "^1.0.5",
"babel-polyfill": "^6.23.0",
"core-js": "^2.4.1",
"datatables.net": "^1.10.15",
"datatables.net-buttons": "^1.5.1",
"datatables.net-dt": "^1.10.15",
"datatables.net-rowgroup-dt": "^1.0.2",
"ngx-bootstrap": "^1.9.0",
"ngx-mydatepicker": "^2.0.9",
"ngx-rating": "0.0.9",
"npm": "^5.7.1",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.1",
"systemjs": "0.19.40",
"ts-helpers": "^1.1.1",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@types/datatables.net": "^1.10.1",
"@types/jasmine": "2.5.36",
"@types/jquery": "2.0.45",
"@types/node": "^6.0.46",
"canonical-path": "0.0.2",
"concurrently": "^3.2.0",
"jasmine-core": "~2.4.1",
"jquery": "^3.2.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"lite-server": "^2.2.2",
"lodash": "^4.16.4",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"tslint": "^3.15.1",
"typescript": "~2.1.0"
},
"repository": {}
}

DataTable is not a function

$
0
0

Hi all,
I'm taking the first steps on yii framework and datatables.
I'm trying to use DataTables on yii but i'm facing this issue:

Uncaught TypeError: $(...).DataTable is not a function
at HTMLDocument.<anonymous> (table_page:65)
at c (jquery.min.js:4)
at Object.fireWith [as resolveWith] (jquery.min.js:4)
at Function.ready (jquery.min.js:4)
at HTMLDocument.q (jquery.min.js:4)

The CODE i'm using:

<HTML>
<HEAD>
<TITLE>My first HTML document</TITLE>

 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">    
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>

  <script type="text/javascript" class="init">
    $(document).ready(function() {
var table = $('#example').DataTable();

$('#example tbody').on('click', 'tr', function () {
    var data = table.row( this ).data();
    alert( 'You clicked on '+data[0]+'\'s row' );
} );

} );
</script>

</HEAD>
<BODY>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
(...)

When i use this code outside Yii this is working properly.
Anyone can help me?
Thanks in advance!

Column width jumping when transitioning from fixed headers to non on first transition

$
0
0

Video link since hard to explain: https://photos.app.goo.gl/0Nvv2xAm9fa7r1NI2 Couldn't find a reference in the forums for my particular issue so making a new post.

I'm using the fixed headers extension with datables and an ajax data source. On the first load, the columns are sized correctly, and the header row is part of the table. When scrolling down, the header row correctly converts to a fixed header row. (offset by a custom amount). When scrolling back up to the point at which the fixed header transitions back into a table header, the columns widths appear to jump. I can't pinpoint any specific reason why this would be happening.

Created with following

/*
 * This combined file was created by the DataTables downloader builder:
 *   https://datatables.net/download
 *
 * To rebuild or modify this file with the latest versions of the included
 * software please visit:
 *   https://datatables.net/download/#bs/dt-1.10.16/af-2.2.2/b-1.5.0/b-colvis-1.5.0/b-html5-1.5.0/b-print-1.5.0/cr-1.4.1/fc-3.2.4/fh-3.1.3/r-2.2.1/rg-1.0.2/rr-1.2.3/sl-1.2.4
 *
 * Included libraries:
 *   DataTables 1.10.16, AutoFill 2.2.2, Buttons 1.5.0, Column visibility 1.5.0, HTML5 export 1.5.0, Print view 1.5.0, ColReorder 1.4.1, FixedColumns 3.2.4, FixedHeader 3.1.3, Responsive 2.2.1, RowGroup 1.0.2, RowReorder 1.2.3, Select 1.2.4
 */

/*! DataTables 1.10.16
 * ©2008-2017 SpryMedia Ltd - datatables.net/license
 */

Datatables Initialization - currently using

            'columns': [
                { data: 'productionDueDate', width: 100, 'class': 'production-due-date-cell' },
                { data: 'bookstem', 'class': 'title-information' },
                { data: null, orderable: false, width: 100 },
                { data: null, width: 100, orderable: false },
                { data: 'runTime', width: 100, orderable: false },
                { data: 'ipsShipDate', width: 100 },
                { data: null, width: 100, orderable: false },
                { data: 'hardcoverPublishDate', width: 100 },
                { data: null, width: 100, orderable: false }
            ],
//          'responsive': true,
            'lengthMenu': [ 10, 25, 50, 100, 200, 400 ],
            'order': [ 1, 'desc' ],
            'autoWidth': false,
            'processing': true,
            'serverSide': true,
            'searchDelay': 600,
            'stateSave': true,
            'paging': true,
            'fixedHeader': {
                'header': true,
                'headerOffset': 51
            },
            'ajax': function(data, callback, settings) {
                data = $.extend(data, {
                    productionDateFrom: TitleStatusView.dom.input_productionDateFrom.val(),
                    productionDateTo: TitleStatusView.dom.input_productionDateTo.val()
                });
                TitleStatusView.tableFilterParams = data;
                Tantor.ajaxWrapper({
                    data: data,
                    url: '/production/title-status/get-datatables',
                    success: function(response) {
                        callback(response)
                    }
                });
            },
            'createdRow': function(row, data, dataIndex) {
                            // change row stuff
            }

Custom condition on a button

$
0
0

Hello Allan,

Could you please clarify if it is possible to set custom JS check whether button should be active or not?
Basically, I'd want to implement custom "jscheck" extension but I can't find a way to pass JS expression to a button on table initialization.

Checkbox Column is only working for the first 10 records

$
0
0

Hi,

I use a datatable with pager and checkboxes to update data. The data comes from SQL Server via Ajax and WebMethods. For some reason I can only update the first 10 records. After that, the click event is no longer fired for the checkbox.
Can anyone help me with this?

Thank you!

Column header height too tall in Internet Explorer and Firefox?

$
0
0

I have a dataTable that looks great in Chrome. However, in IE and Firefox, the header and footers are too tall. Is there a CSS value or setting that will correct the height?

Chrome: Height of header is correct:

Internet Explorer: Height of header is too tall:


Change default ordering?

$
0
0

Hey Guys,
I am pretty newbie when it comes to a lot of this stuff. I can not for the life of me figure out how to change the default ordering of my table. The first row is just a row of dates and I would like the newest dates to be at the top of the table not the bottom. Please help!

How to show all row in data table by show select?

$
0
0

Hi, Please let me know, how to show 500, 1000, & all row by selecting in show box.

Cover page for Datatables-generated pdf? Or flexible margins?

$
0
0

We're using datatables to generate printable reports on a vast amount of data -- we're being asked to include either some specific header data or a cover page for these printable reports. This header data is really too much to include in a top margin which is why we're trying to see if it's possible to have a cover page generated. Has anyone tried this or would know how to go about doing it for the PDF-version of a datatables table? Cover page would remain the same for all tables generated -- it would just have a hard-coded title.

Or alternatively, is it possible to have margins that change on a page-by-page basis? If anyone has insight, would greatly appreciate it.

Adding Date Range filter plugin in specific Datatable

"Uncaught RangeError: Maximum call stack" for a custom button that doesn't work with the data !

$
0
0

Trying to add an import CSV button to a datatables ( 7 columns, ~700 rows, loaded by ajax)

Tried different ways, this one "should" work : having a custom hidden form inside the button and triggering the file input screen selection on button action.

        text: '<span class="ion-ios-cloud-upload-outline">&nbsp;Import</span>'
        +'<form style="display: none;" action="import.php" method="POST" id="csv_import">'
        +'<input type="file" id="csv_import_file" name="csv_import_file_name" onchange="this.form.submit();"></form>'
        action: function( e, dt, node, config ) {
            var input_file = $(node).find('#csv_import_file');
            console.log(input_file.attr('name')); // works and shows the input's name in the console.
            input_file.click();
            return false;    
        }

(full js code on https://pastebin.com/ys7NbkFM , doesn't format properly here.)

But I keep getting this error on click
_ Uncaught RangeError: Maximum call stack size exceeded
at String.replace (<anonymous>)
at G (jquery.min.js:2)
at Q.get (jquery.min.js:2)
at HTMLButtonElement.dispatch (jquery.min.js:2)
at HTMLButtonElement.y.handle (jquery.min.js:2)
at Object.trigger (jquery.min.js:2)
at HTMLInputElement.<anonymous> (jquery.min.js:2)
at Function.each (jquery.min.js:2)
at w.fn.init.each (jquery.min.js:2)
at w.fn.init.trigger (jquery.min.js:2)_

The button and its action are not even touching the data ...
What am I missing ?

change the grid size at run time

$
0
0

Hi,
How can I change the grid size at runtime (after initialization)
note :My grid is in a "div" that the user can resize with the mouse

Thanks

scrollx and width of headers problem

$
0
0

Hello there,

I would like to ask for help in regarding to my issue that last for some time and can not find solution that would solve my problem.
I am having data table here with data from MySQL database. All works fine, but some of tables are too long in height that I would need to use vertical scroll with at least 400px there.
When I use scrollX, scroll appears, but it will cut the table header and I have no clue, where or how to fix this issue.

I would really appreciate any help and solution that will sort my issue out.

Regards,
Robert


Is there a way to create (handle) expandable / collapsible editor form..

$
0
0

Basically, what I want is..

on the form there should be a HIDE button .. and when user clicks the button some of the fields (Dynamically added.. using dependent) should be hidden.. and HIDE should be changed to SHOW... and when user clicks SHOW button.. the hidden fields should reappear..

Kindly direct me into right direction.. any example would be really appriciated...

How can i change cell value of cached table ?

$
0
0

Hi, I'm using page cacheing as described in the piplining example in my table.

Now i need to reload one row when click on a table inside that row.

First i send a request to server to edit the record and if request is success i just changed cell value using table.cell( row, col).data("Accepted").invalidate();

But this is not working as i expected. New value, Accepted is immediately disappear after setting it. I think it happens because the caching. Is there any way i can update cached data ?

i want to get a currency amount format with two digits decimal values, Please advise me ?

$
0
0

My datatable shows only round values in amount column , i want to have a values with currency format like $233.25 instead of $234.00.
HTML table head code
<thead>
<tr>
<th>Date</th>
<th>SalesNumber</th>
<th>AmountExclGST</th>
<th>GST</th>
<th>TotalAmount</th>
<th>ContactPerson</th>
<th>Status</th>
<th>FullyPaid</th>
<th>Attachment</th>
</tr>
</thead>

javascript code for columns:-

{ 'data': 'AmountExclGST',

 'render': $.fn.dataTable.render.number(',', '.', 2, 'S$')

},

My result column :- amount S$234.00 correct format should be Amount S$233.25 Please advise me what should i need to do , in order to get currency format with decimal values ?

Field type for numbers

$
0
0

I was looking for a field type for numbers. "<input type="number">". I guess that's what is missing. Ain't it?

How update field value of parent table with a field value in child table

$
0
0

I have a parent table called "contacts" and a child table called "visits".
For each contact I can have multiple visits.
When, at a certain visit, the contact decides to sign a contract, I need to change a value of a parent table "contacts" field from 0 to 1 to indicate that the contact has become a customer.
I do not know how to do...

Viewing all 82464 articles
Browse latest View live


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