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

Datatable Conflict with js

$
0
0

can u please help me this problem.
i have a template, but if i use datatable is not working, in other template work. js problem.
thanks


Buttons in cell won't work with ajax source

$
0
0

... but they do work with javascript source.

Here's a simple test case.

http://live.datatables.net/fupinifi/2/edit

If I move the input data to a file and use ajax to load it, the button clicks stop working. I have the few lines to load the ajax source commented out in the script. The content of example.json is just the same array that I have assigned to 'data' at the top of the script.

Appreciate some help!!

LeftJoin with multiple conditions and Where Clause

$
0
0

Using the information I've been able to find, here is the code I'm using with DataTables Editor..but when I run this I get an SQL error near the Where clause. I don't know how to see the SQL, so I can't debug it. Any idea what I'm doing wrong? Thanks

$editor = Editor::inst( $db, 'tbl_schedule','schID' )
->fields(
Field::inst( 'tbl_schedule.userid_fk' ),
Field::inst( 'tbl_schedule.courseID_fk' ),
Field::inst( 'tbl_schedule.schDate' ),
Field::inst( 'tbl_schedule.schOrder' ),
Field::inst( 'tbl_record_session.timeStamp' )
)

->leftJoin( 'tbl_record_session',
    'tbl_schedule.userid_fk', '=',
            'tbl_record_session.userid_fk AND
            tbl_schedule.courseID_fk = tbl_record_session.courseid_fk AND
            tbl_record_session.sessionNumber=tbl_schedule.schOrder'
           )


->where( 'tbl_schedule.userid_fk', 296 )
->where( 'tbl_schedule.courseID_fk', 2)
->process( $_POST )
->json();

HTML tags when sending email

$
0
0

Greetings,
Whenever a user edits a record, i'm sending an email to a distribution group which shows the values. I'm trying to wrap the values in an html tag so its easier to read on the email. I tried the following but it prints the html tag instead:

Editor::inst( $db, 'parts' )
->fields(
Field::inst( 'firstname' )->validator( 'Validate::notEmpty' ),
Field::inst( 'lastname' )->validator( 'Validate::notEmpty' ),
Field::inst( 'status' ),
Field::inst( 'email' ),
Field::inst( 'company' ),
Field::inst( 'tag' ),
Field::inst( 'serialnumber' ),
Field::inst( 'requestpartnumber' ),
Field::inst( 'requestpartquantity' ),
Field::inst( 'updated_date' )
->validator( 'Validate::dateFormat', array(
'empty' => false,
'format' => 'm-d-Y g:i A'
) )
->getFormatter( 'Format::datetime', array(
'from' => 'Y-m-d H:i:s',
'to' => 'm-d-Y g:i A'
) )
->setFormatter( 'Format::datetime', array(
'from' => 'm-d-Y g:i A',
'to' => 'Y-m-d H:i:s'
) )

)

->on( 'postEdit', function ( $editor, $id, $values, $row) {

mail( me@gmail.com', 'Parts ETA', ''.implode('<br>', $values).'' );

} )
->process( $_POST )
->json();

Any idea's how to add an HTML header?

Export to Excel hangs on IE11 (>10k records)

$
0
0

Hello

Im using datatables for displaying data on the webpage. Have also added and Export button which would export the data in Excel format.
There are around 10k records that would be displayed /filtered. The export to excel doesnt work when tried from IE11 however the same works from Chrome (Version 42.0.2311.13).
Can you advise if this is a known issue and is there any fix for it.

Code snippet from js file:

var table = $('.tableContent').DataTable({
    "autoWidth": false,
    "pageLength": 50,
    dom : 'lBfrtip',
    buttons : [ {
        extend : 'excel',
        text : 'Export to Excel',
        exportOptions : {
            modifier : {
                // DataTables core
                order : 'index',  // 'current', 'applied', 'index',  'original'
                page : 'all',      // 'all',     'current'
                search : 'none'     // 'none',    'applied', 'removed'
            }
        }
    } ],
    "columnDefs" : [{
        "targets" : [ 0, 1, 2, 8, 9, 10, 11,  17, 18 ],
        "visible" : true,
        "searchable" : true
    }, {
        "targets" : [ 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 19, 20, 21 ],
        "visible" : false,
        "searchable" : false
    }]
});

Issues with moment.js and localization

$
0
0

Hi Allan,

I am using moment.js to format dates. I have included the MomentJS-2.13.0 Javascript. In addition I am using two locales:

<!--    Locales for moment.js-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/de.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/en-gb.js"></script>

To initialize moment.js I do this:

//Moment.js (date time) location settings
if (lang === 'de') {
    moment.locale('de');
} else {
    moment.locale('en-gb');
}
// Return today's date and time
var currentTime = new Date();

The Data Table uses this - and it works perfectly fine. For German (lang === 'de') it returns 'DD.MM.YYYY' else it returns the English Version of 'DD/MM/YYYY'.

{   data: "rfp.start_date",
    render: function ( data, type, row ) {
            return moment(new Date(data)).format('L');
    }
},

My problem is with Editor. The only thing that works here is the default unfortunately which correctly returns the current date in the German or English format.

fields: [ {
                label: "Start Date:",
                name:  "rfp.start_date",
                type:  "datetime",
                def:   function () { return moment(currentTime).format('L');},
                format: 'DD.MM.YYYY',
                opts:  {
                    showWeekNumber: true,
                    momentLocale: 'de'
                }
            }, {
                label: "End Date:",
                name:  "rfp.end_date",
                type:  "datetime",
                def:   function () { return moment(currentTime).format('L');}
            } ]

"Start Date" in this fashion only works for German because Editor forced me to hard code the format to be 'MM.DD.YYYY'. Editor does not accept the format 'L' which is a moment.js standard format used with localization. You can also see it in the respective moment locale scripts mentioned above. I tried to use a global variable predefined with one of the two formats but that produced an error. So how can I localize this? How can I preset the format so that is used correctly by Editor since it does not acceopt 'L'?

And there is another issue: Editor ignores "momentLocale: 'de'". "showWeekNumber" works however. For that reason my date picker is only in English and not shown in German.

Let's assume I get "momentLocale" working: How do I dynamically set the locale to either German or English?

"End Date" is even worse: Only the default works fine in German or English. Once you start editing the date it shows it in 'YYYY-MM-DD'. For the German language setting it starts with the default of '03.02.2017'. Then I open the date picker which is in English only and if I select February 4th the date picker returns '2017-02-04' which is a problem ...

Please help!

How to add a Refresh Tab button

$
0
0

Please describe exactly how to add a button that'll only refresh the current tab.

Ideally the Buttons plugin would offer a built-in Refresh button but it does not. We fetch data with "ajax": {"url":"getmyajax.foo"} so hopefully the process of adding a button that reloads it, and the tab itself, is moderately straightforward. Thanks :-)

How to Resize column of data table

$
0
0

Hi All,

I am not getting the solution of resizing of data table as per requirement, so if any body have the solution so help me for resizing the data table.


columnDefs and savestate (1.10.13)

$
0
0

What I want to achieve is a column toggle (have a set of available columns, and allow them to be toggled). The way I was attempting to achieve this was:

a) Build the DOM with all columns
b) Initialize the table with the columns that I want
c) Present the selection of columns to the user, and if they toggle columns repeat steps (a) and (b)

I know this isn't terribly efficient, but my table size is relatively small, and mostly it works well if savestate is not enabled.

If savestate is enabled, then the "visible" property of the column appears to be ignored.

This works, and hides the column(s), but doesn't save state:

$('#' + tableid).DataTable(
            {
                "columnDefs": [
                    {
                        "targets": [0],
                        "visible": true,
                        "searchable": false
                    },
                    {
                        "targets": [1, 2],
                        "visible": true,
                        "searchable": true
                    },
                    {
                        "targets": [3],
                        "visible": false,
                        "searchable": true
                    }
                ]
            }
        );

This saves state properly, but shows all columns:

$('#' + tableid).DataTable(
            {
                "columnDefs": [
                    {
                        "targets": [0],
                        "visible": true,
                        "searchable": false
                    },
                    {
                        "targets": [1, 2],
                        "visible": true,
                        "searchable": true
                    },
                    {
                        "targets": [3],
                        "visible": false,
                        "searchable": true
                    }
                ],
                stateSave: true
            }
        );
    };

To be honest, I would be OK with any of the following outcomes:

1) A widget that would allow me to toggle columns
2) A way of toggling columns on an initialized table, rather than destroying and re-creating (am I missing something in the docs?)
3) A complete hack that involves messing with the saved state

I really like to have state saved, since re-drawing columns isn't great user experience if they have made search or other selections, but I also need to be able to toggle columns, since I potentially have too many to comfortably fit on a page and some are only needed occasionally.

Thanks,

Dave

Editor Ajax URL with Parameters

$
0
0

We freshly purchased Editor, but we are bloody beginners, maybe somebody have a hint for us.

We are using Scripts made by the editor generator, wich works very good. But in one script we try to pass a Parameter via ajax, which ist failing.

Our script receive datas without any problems as long as we pass URL like:

ajax: "php/table.tbl_prices.php",

But if we try to pass an URL with Parameter for a WHERE-Condition like
ajax: "php/table.tbl_prices.php?project_id=2",

our script do not receive any data.
If we run the "table.tbl_prices.php?project_id=2"-Script directly, it will return Data like:
{"data":[{"DT_RowId":"row_235","project_id":"31","price_group":"A","price":"3555.00"}......
So the script table.tbl_prices.php can handle the parameter.

How we pass the parameter correctly?

More easy would be, if we could pass the WHERE-condition directly from my script like:

var editor = new $.fn.dataTable.Editor( {
where: ['project_id', <?php echo $project_id; ?>),
ajax: "php/table.tbl_prices.php?project_id=2",
table: '#tbl_prices'.....

But I think this in not possible. Is there another way to pass variables to table.tbl_prices.php?

show/hide list group items from a table row/

$
0
0

Hi ,

I have a table which has a button (toggle)as one of the column item in every row. Upon clicking it I need to collapse/expand a list group that is constructed at the time when the table was constructed. Initially its hidden. Is it possible to do this in data tables? I see examples showing how a row can show certain details, but those include additional data that come upon request from ajax etc. My list group is already present within the table.

How To Popup a Dialog

$
0
0

Hi There, i would like to get dynamical data displayed on a Jquery Dialog. I want that to be triggered when i click on datatable row. Can someone please give an example on how to on this.

Is possible to filter blank fields on multi_select (YADCF)?

$
0
0

I want to know if its possible to get the rows with empty fields on this columns selecting (" ") or ("EMPTY") or something else on the column filter. I have a fiddle to explain this.

At first column (Status) I have three values (ON, OFF, (EMPTY)). My problem is to get the rows with empty values (Same row as PR00000003, PR00000005) selecting empty value on the filter.

Thanks in advace.

Missing array values using fnGetHiddenNodes function.

$
0
0

Hi Guys,

I'm new to PHP and i just discovered the DataTables plugin, i think it's awesome!
I'm working on a project where i use this plugin within a html form, to display data and let the user input a value using an input field.
Within the form i use another input field with the attribute 'hidden' to store an id value (product id).

When submitting the form i use the fnGetHiddenNodes() function to retrieve user inputs on the pages that are not being displayed.
It all works fine, but somehow i'm missing "id"'s when i submit the form WITH this hidden input field.
When i submit the form using only the quantity input field it all works fine...

  • The data is retrieved through the PDO interface sqlsrvr.

Any thoughts?, here is some code...

DataTables initialize and fnGetHiddenNodes()

` <script type="text/javascript" charset="utf-8">

    jQuery.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( settings )
    {
        var nodes;
        var display = jQuery('tbody tr', settings.nTable);
        var api = new jQuery.fn.dataTable.Api( settings );
        nodes = api.rows().nodes().toArray();
        /* Remove nodes which are being displayed */
        for ( var i=0 ; i<display.length ; i++ ) {
            var iIndex = jQuery.inArray( display[i], nodes );
            if ( iIndex != -1 ) {
            nodes.splice( iIndex, 1 );
            }
        }
        return nodes;
    };

    $(document).ready(function() {

        var oTable = $('#example').dataTable({
          "bSort": false
        });

        $('#button').click( function () {
        var form = $('#form');
        var nHidden = oTable.fnGetHiddenNodes();

        $(nHidden).appendTo(form);
        form.submit();
        } );
    });
</script>`

HTML & PHP to echo value from $row id.

` <form id="form" method="post" action="order.php">
<table id="example" class="display" cellspacing="0" width="100%">

               echo "<tr>";
                echo "<td> <input type='number' name='quantity[]'></td>";
                echo "<td> <input type='number' name='id[]' value='", $row['@@RRNO'],"'></td>";
                echo "</tr>";

</table>
<input type="submit">
</form>
`

-note-the-687-entries.">-note-the-687-entries.">Output -> note the 687 entries.

see image of printscreen

On the php side to get array values

$array=array_values($_POST['id']); print_r($array);

-note-only-498-array-values-(indexes)">-note-only-498-array-values-(indexes)">Output -> note only 498 array values (indexes)

see second image of printscreen

KeyTable bootstrap stylesheet buggy in IE


TableTools Strips not only html but text too?

$
0
0

I have following html in the column

<td><span class="nickname-editable editable editable-click" title="Account Nickname" data-model="account" data-name="nick_name" data-value="14 District" data-placeholder="Account Nickname" data-url="/accounts/16979">14 District</span></td>

When i'm exporting i expeting 14 District to go though, but i always get blank column, any hints?

Related code

oTableTools: { aButtons: [{ sExtends: "collection", sButtonText: "Export", sButtonClass: "btn btn-primary btn-sm", aButtons: [{ sExtends: "xls", sButtonText: "Excel", sFileName: "*.xls" }, { sExtends: "pdf", sPdfOrientation: "landscape", }] }], sSwfPath: "/swf/copy_csv_xls_pdf.swf" },
This is true for both PDF and XLS

Individual search (select input) value stored in cookies

$
0
0

I have problem with my datatables, im using individual search for each column and the last column using select input. When i select a value, it seem the value always stored on cookies or localstorage on my browser. So, after i select a value, datatables always send it to my controller even if there is nothing on my select/input. I need to clear my history, cache, cooking and other option to reset the value. Anyone has facing this problem before?

First Column disappears when changing from responsive mode(+/-) to standard mode

$
0
0

Here is a reproduction:
jsbin.com/dezuga/edit?js,output

When you resize the width of the output page, in responsive mode (when the expand/collapse signs appear) you can see the "name" column, if you enlarge the width of the page and the table switches into standard mode the "name" column is hidden.

Why is that?

Datatables.net and large dataset in C#

$
0
0

hi,
i've just started using datatables and i'm struggling with the performance.. its more of a C# question than datatables but i wondered if anyone can assist.
so i've been using this: https://github.com/ALMMa/datatables.aspnet
the dataset i'm using is about 12k records so not massive... the performance problems i get is when calling .Count() on the dataset returned from EntityFramework

    public IActionResult MyDataTableTestPageData(IDataTablesRequest request)
    {
        var model = _mediator.Send(new GetMyData
        {
            Request = request
        });

        var data = model;

        // Global filtering.
        // Filter is being manually applied due to in-memmory (IEnumerable) data.
        // If you want something rather easier, check IEnumerableExtensions Sample.
        var filteredData = String.IsNullOrWhiteSpace(request.Search.Value)
            ? data
            : data.Where(
                _item =>
                    !string.IsNullOrEmpty(_item.FirstName) &&
                    _item.FirstName.ToLower().ToLower().Contains(request.Search.Value.ToLower()));

        // Paging filtered data.
        // Paging is rather manual due to in-memmory (IEnumerable) data.
        var dataPage = model.Skip(request.Start).Take(request.Length).ToDataTableViewModel();

        // Response creation. To create your response you need to reference your request, to avoid
        // request/response tampering and to ensure response will be correctly created.
        var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

        // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
        // response to a json-compatible content, so DataTables can read it when received.
        return new DataTablesJsonResult(response, true);
    }

removing the data.Count() and filteredData.Count() the call is instant because of the deferred nature of IEnumerable.
what can i do to improve the performance?

cheers,

Custom Search Option

$
0
0

Hi,

I would like to have the option of searching only in one column only by typing <columnName>:<string> in the search box. Is this possible? Some of my columns have icons in it like:

{
"targets": 4,
"render": function (data, type, full, meta) {
// If it is rendering the cell contents
if (type === 'display') {
switch (data) {
case 0:
return '<span style="font-size:75%" class="fa-stack fa-lg"><i class="fa fa-unlock fa-stack-2x" style="color:#71BF3D"></i></span>';
case 1:
return '<span style="font-size:75%" class="fa-stack fa-lg"><i class="fa fa-lock fa-stack-2x" style="color:#E74C3C"></i></span>';
default:
return '<span>-</span>';
}
}
return (isNaN(data)) ? -1 : +data;
}
}

Would this kind of values actually work with the search box?

I'm fairly new in using DataTables, so please be gentle :smile:

Thanks in advance! :blush:

Viewing all 81384 articles
Browse latest View live


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