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

Strategies for handling session timeout?

$
0
0

Apologies for the long question; this is half "how do I get this to work," and half "do I even want this to work?"

I have a case where this is happening:

  • the user logs in, loads a page with a DataTable, & brings up one or more records in Editor
  • they wander off; their session times out
  • they come back and hit submit
  • the server sends back an HTTP 302 redirect to the login page (and the login page is being requested; more on this below)
  • Editor displays "A system error has occurred" as the error message, with a "more information" link to datatables.net

My first thought was that I wanted to display a more helpful error message ("Dude, you need to change your fiber intake" or whatever). However, it turns out that things are actually a little more complicated than that: some of my Editor fields use dependent to rebuild option lists when their values change (e.g., if you're trying to assign Necrobutcher a role in a black metal band, and you choose Mayhem as the band, I fetch Mayhem's list of available roles, which will have Lead Keytar filtered out on the server side), and those ajax calls are getting 302s (followed by 200s as the browser--or jQuery?--succesfully requests the login page from the redirect, and then my code croaks when it gets the HTML login page instead of the JSON list of roles).

So, in some cases, life may be bad before they hit submit, so wanting to handle the 302 in Editor's "submit" ajax call may be fundamentally misguided. How are other people handling this sort of thing?


If it turns out that the "submit" ajax call is the right place to handle the 302, I see this question which gives an example of handling an error by calling alert() and then notifying Editor, and I see the ajax documentation explaining how to use a function instead of an object, but I'm having trouble getting it working.

Here's what I've got currently, before making any changes.

//  this guy is in a file which is shared by all my DataTables pages
var editorAjax = function( url ) {
    return {
        'url': url,
        contentType: 'application/json',
        data: function ( d ) {
            return JSON.stringify( d );
        }
    };
};

//  this is how I'm calling that in my various tables/pages
editor = new $.fn.dataTable.Editor( {
    ajax: editorAjax( '/my/nifty/api' ),
    table: '#my_nifty_table',
    ...

Adding an error element to that object returned by my editorAjax() function looks like this:

var editorAjax = function( url ) {
    return {
        'url': url,
        contentType: 'application/json',
        data: function ( d ) {
            return JSON.stringify( d );
        },
        error: function ( xhr, jqAjaxerror, thrown ) {
            if ( xhr.status == 302 ) {
                //  call error() on my editor instance, once I get my
                //  hands on it?  (It doesn't exist at this point;
                //  editorAjax() is called on the way in to the Editor
                //  constructor.)
            }
            //  what else do I need to do in here?
        }
    };
};

The main problem here is that this doesn't actually get called with the 302! It looks like, under the covers, the browser is following the redirect & fetching the login page, and then this gets hit with the jQuery JSON.parse error when it tries to parse the login page HTML as JSON. (And at that point, xhr.status is 200, because the second HTTP request succeeded!)

Returning a function instead of an object behaves the same, and looks like this:

var editorAjax = function( url ) {
    return function ( ignoredMethod, ignoredURL, data, success, error ) {
        $.ajax( {
            type: 'POST',
            url:  url,
            contentType: 'application/json',
            data: JSON.stringify(data),
            dataType: 'json',
            success: function ( json ) {
                success( json );
            },
            error: function ( xhr, jqAjaxError, thrown ) {
                //  we don't get xhr.status == 302 in here...
                error( xhr, jqAjaxError, thrown );
            }
        } );
    };
};

So, if (IF!) handling the session timeout here is the right thing to do... how do I do it? And if not, how should I handle it?


How to use Export Buttons with Datatable Modal (i.e. Responsive Datatables)

$
0
0

I'm using responsive datatables as my columns are more than 20. When i moved to Modal Datatables, the export buttons are not displaying.

The 'Tab' Key can't work after one column updated - An Editor Problem

$
0
0

Hey, guys. I'm a datatables fans, and trying to use editor in my application.

I download the last version by DataTables download builder. https://datatables.net/download

Try to use the editor's inline mode, like this: Tab between columns, https://editor.datatables.net/examples/inline-editing/tabControl.html

My problem : the tab key can't work after the server side response, you can't use the Tab key to edit through the whole line.

here is my test case: http://114.215.164.199:8080/editor/resource/query.do

Any advice would be appreciated! thank you.

Clickable truncate JS

$
0
0

For whom it may interest
If you are having the same issue as me with a lot of data for a column, that you need to check some times, but not want to show at all times, this code might help you. Truncate is here clickable - on/off.

$(".truncate").on("click", function() {
                var index = $(this).index() + 1;
                $('table tr td:nth-child(' + index  + ')').toggleClass("truncate");
            });

code for CSS:

.truncate {
    max-width:80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    }

Best regards
Claus

Multi Level Group with Custom Heading

Editor buttons do not show

$
0
0

Hi,
I've just started with datatables and editor. I've build a small example, datatables work fine, but I can't get the editor buttons to show up. Can anyone have a look at the code and point me to the right direction?
I do not get any errors or output in the developer console. All .js and .css files seem to load correctly.

Thanks in advance,
Thomas

<!DOCTYPE html>
<html lang="en">


<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.1/css/buttons.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>

    <link rel="stylesheet" type="text/css" href="/editor/css/editor.dataTables.min.css">
    <script type="text/javascript" src="/editor/js/dataTables.editor.js"></script>

    <meta charset="UTF-8">
    <title>Title</title>
</head>

<script type="text/javascript">

    var editor; // use a global for the submit and return data rendering in the examples

    $(document).ready( function () {

        editor = new $.fn.dataTable.Editor( {
            ajax:  '/company/json',
            table: '#example',
            fields: [
                { label: 'Name', name: 'name' },
                { label: 'Address',  name: 'address'  },
                // etc
            ]
        } );

        $('#example').dataTable( {

            dom: 'Bfrtip',
            processing: true,
            serverSide: true,
            ajax: {
                url: '/company/json',
                type: 'POST'
            },

            columns: [
                { data: "id" },
                { data: "name" },
                { data: "address" },
                { data: "age" },
                { data: "action" }

            ],

            select: true,
            buttons: [
                { extend: 'create', editor: editor },
                { extend: 'edit',   editor: editor },
                { extend: 'remove', editor: editor }
            ]

        } );

    } );

</script>



<body>
<h1>TEST</h1>
<br><br>


<table id="example" class="display" style="width:100%">
    <thead>
    <tr>
        <th>ID</th>
<th>NAME</th>
<th>ADDRESS</th>
<th>AGE</th>
<th>Actions</th>

    </tr>
    </thead>
    <tbody>
    </tbody>
</table>


</body>
</html>

If checkbox in the editor field became selected, change the content of the editor field and store it

$
0
0

Hello everybody

I've been sitting on a more complex topic for days.

I have a lot of input fields with prices in an editor form (e.g. db.reg_price and db.red_price). You can enter this by hand. Underneath there is the possibility to activate a checkbox. If this has been activated, the array should be taken from another table with these prices (reg_price and red_price without db. ).

Up to this point, this also works very well. Even the data in the table contain the values (reg_price and red_price) after saving the form. BUT! These values are not updated in the database in the original variables (db_reg_price and db_red_price). Only when you go into the editor field again and save again, does it take the values into the database.

  1. Is there a possibility to update both variables with this new values from the second table?

I made some tests with ->on('preEdit', function and also with postEdit and so on in the staff.php. Also with editor.on( 'preSubmit', function in the Javascript. But I don't find the right solution.

  1. Is there a possibility to block the fields in editor form if the checkbox were activated?

I'll be at one's wit's end....

Thanks a lot.
Mac

Javascript:

var editor; 

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
fields: [
   {
                type: "select",
                label: "Select price package:",
                name: "event.db_price_select_form",
                placeholder: "Please select"
            }, {
                label: "Regular price:",
                name: "event.db_reg_price",
                fieldInfo: "Format: 16.00",
                    
                }, {
                label: "Reduced price:",
                name: "event.db_red_price",
                fieldInfo: "Format: 16.00",
            },
.....

var table = $('#example').DataTable( {

 columns: [
            
            { data: "event.db_price_select",
                render: function (data, type, row) {
                    if (row.event.db_price_select == 1) {
                        return 'Yes';
                    } else {
                        return 'No';
                    }
                }
            },
            { data: "event.name_price_pack" },

            { data: "event.db_reg_price",
            render: function (data, type, row) {
                    if (row.event.db_price_select == 1) {
                        row.event.db_reg_price = row.price.reg_price;
                        return row.price.reg_price;
                    } else {
                        return row.event.db_reg_price;
                    }
                }
            },
......

staff.php:

......
        Field::inst( 'event.db_price_select_form' )
            ->options( Options::inst()
                ->table( 'price' )
                ->value( 'id' )
                ->label( array ( 'name_price_pack', 'reg_price', 'red_price' ))
            )
            ->validator( Validate::dbValues() ),
            Field::inst( 'price.name_price_pack' ),
            Field::inst( 'price.reg_price' ),
            Field::inst( 'price.red_price' ),

        Field::inst( 'event.db_reg_price' ),
        Field::inst( 'event.db_red_price' ),

->leftJoin( 'price', 'price.id', '=', 'event.db_price_select_form' )

.....

bootstrap modal is not showing data tables latest version

$
0
0

My question is pretty simple.I tried everything but my modal is not showing can anyone help me please ..
My client side Code:

  $(function() {
        
        var GridView =  $('#users_table').DataTable({
            bprocessing: true,
            bserverSide: true,
            ajax: '{{ route('users.lists') }}',
            deferRender: true,
            columns: [
                { data: 'id', name: 'id' },
                { data: 'name', name: 'name' },
                { data: 'email', name: 'email' },
                { data: 'action', name: 'action'},
                
            ]
        });

        $('#users_table').show();
        GridView.columns.adjust().draw();
    });

My Server Side code is:

 return Datatables::of(User::all())
                                   ->addColumn('action',function($user){
                            return '<button data-toggle="modal" data-target="#rolesModel" class="btn btn-success">Mss</button>
                                    <a data-toggle="tooltip" title="Edit" class="btn btn-danger"><i class="fa fa-edit"></i></a>';
                                             
                                   })
                                   ->make(true)
                                  ;

My rolesModel at the bottom of the page

<!-- Modal fade in scale up -->
<div class="md-modal md-fade-in-scale-up" id="rolesModel">
    <div class="md-content">
        <h3>Modal Dialog</h3>
        <div>
            <p>This is a modal window. You can do the following things with it:</p>
            <ul>
                <li><strong>Read:</strong> modal windows will probably tell you something important so don't forget to read what they say.</li>
                <li><strong>Look:</strong> a modal window enjoys a certain kind of attention; just look at it and appreciate its presence.</li>
                <li><strong>Close:</strong> click on the button below to close the modal.</li>
            </ul>
            <p>
            <button class="btn btn-danger md-close">Close me!</button>
            <button class="btn btn-success md-close">Some button</button>
            </p>
        </div>
    </div><!-- End div .md-content -->
</div>

I fetch the data and show in table successfully.My only concern is to show model at click.Please help me . i have been traped inside it. thanks a lot.


bootstrap modal is not showing

$
0
0

My question is pretty simple.I tried everything but my modal is not showing can anyone help me please ..
My client side Code:

$(function() {
       
      var GridView =  $('#users_table').DataTable({
          bprocessing: true,
          bserverSide: true,
          ajax: '{{ route('users.lists') }}',
          deferRender: true,
          columns: [
              { data: 'id', name: 'id' },
              { data: 'name', name: 'name' },
              { data: 'email', name: 'email' },
              { data: 'action', name: 'action'},
               
          ]
      });
 
      $('#users_table').show();
      GridView.columns.adjust().draw();
  });

My Server Side code is:

return Datatables::of(User::all())
                                  ->addColumn('action',function($user){
                           return '<button data-toggle="modal" data-target="#rolesModel" class="btn btn-success">Mss</button>
                                   <a data-toggle="tooltip" title="Edit" class="btn btn-danger"><i class="fa fa-edit"></i></a>';
                                             
                                  })
                                  ->make(true)
                                 ;

My rolesModel at the bottom of the page:

<!-- Modal fade in scale up -->
<div class="md-modal md-fade-in-scale-up" id="rolesModel">
    <div class="md-content">
        <h3>Modal Dialog</h3>
        <div>
            <p>This is a modal window. You can do the following things with it:</p>
            <ul>
                <li><strong>Read:</strong> modal windows will probably tell you something important so don't forget to read what they say.</li>
                <li><strong>Look:</strong> a modal window enjoys a certain kind of attention; just look at it and appreciate its presence.</li>
                <li><strong>Close:</strong> click on the button below to close the modal.</li>
            </ul>
            <p>
            <button class="btn btn-danger md-close">Close me!</button>
            <button class="btn btn-success md-close">Some button</button>
            </p>
        </div>
    </div><!-- End div .md-content -->
</div>

I fetch the data and show in table successfully.My only concern is to show model at click.Please help me . i have been traped inside it. thanks a lot.

Node.js - Where clause stopped working after updating Knex

$
0
0

I've got an node.js app in development using Editor and DataTables, that I've just gotten back to after a bit of a break. I updated all the dependencies, and after fixing a few minor things, I'm having a big problem when using the Where clause functionality in Editor. Every time its called I get the following error:

Unhandled promise error: [object Promise]TypeError: The operator "undefined" is not permitted app.js:29 stack: TypeError: The operator "undefined" is not permitted at MSSQL_Formatter.operator (/Dev/members-app/node_modules/knex/lib/formatter.js:203:13)

This was working fine a few months back. Taking the Where clause out, everything works fine. I've tried forcing in the operator to no avail. I'm developing on Mac with VS Code, database is Azure SQL Database.

Any clues??

colReorder: issues with sorting and state reload

$
0
0

I can't get why but with Firefox the sorting is being triggered when dropping a moved column. With Chrome this does not happens.

I've created a fiddle and noticed that it happens also there, even if less frequently: https://jsfiddle.net/42gstmh3/.

I've done deeper tests and found that (on my local project) if I drop it above or below table's thead, the sorting is not called. Could you give me a hint on what I should check to fix this behaviour? Or is it something on your side?

Also, I've noticed that if I save the state, the column headers will be reloaded in the custom order applied with colreorder but data doesn't match with their corrispective headers...data will appear in the data source order (like if no colReorder has ever being applied).

Grid resize is slow

$
0
0

This is 5000 rows X 20 columns.
I already using minified css files. But it is taking around 5 sec to resize.
Whole web app is unresponsive during these 5 seconds of resizing.

Is there a way to show loading overlay onBeforeResize and hide it in OnResize event.
Any suggestions how to keep browser more responsive during the resizing time?

Also browser is freezing during Redraw time. Any help with that?

show only export buttons

$
0
0

Hello,
I was wondering how to hide the datatable ( the table, the search bar etc. ) and only show the dt-buttons for export (copy, pdf, excel...)?
Thank you !

Pre-render child rows (helpful with Angular)

$
0
0

I know how to dynamically create nested tables with row.child("<h1>Content</h1>").show().
But using Angular it's not easy to create dynamic components in the code as strings. It would help if I could prerender the content of the child rows. So the child rows are in the DOM (and connected to all angular events) but not visible, e.g (td omitted):

    <table>
      <tbody>
      <tr><app-content-component content="Content-Row 1" /></tr>
      <tr class="child-row"><app-childcontent-component content="content from child row 1" /></tr>
      <tr><app-content-component content="Content-Row 2" /></tr>
      <tr class="child-row"><app-childcontent-component content="content from child row 2" /></tr>
    ...

Can a row somehow marked as a child row (above I used a class "child-row" just as an example)? So I just need to call row.child.show/hide() to toggle visibility of the child rows?

Losing select2 field value when loading options via ajax

$
0
0

I have a select2 field (problem_field) whose options depend on the value of another field (dependant_field).
I update the options with:

editor.dependent("dependant_field", function (val) {
  $.ajax({
            type: "POST",
            ...,
            success: function (options) {
                editor.field("problem_field").update(options);
    });

If I remove the ajax call and load the options directly then it works.
If I leave the ajax call in place and change the field type to "select" then it works.

So it seems that select field allows you to set value not in options, but select2 does not.
Is there a work around to this?
Something I can do in initEdit to save the field values, and set them after field().update() ?

Kind regards,
Kevan


Select2 dropdown list does not open after second editor openning

$
0
0

Hi

Have a series of select2 field in my editor form.
Everything works find when i open the editor for the first time. But after closing the editor form, and reoppenning it in create or edit mode, the dropdown field is clickable but nothing appear when clicking on it.
I will need to reload the page to get it working again.

{label: "Select type: ",name: "metadata_field_2",type: "select2",opts: {placeholder: "Select a content type",minimumResultsForSearch: 5,multiple: false,closeOnSelect: false,include_hidden: false}, options: generateTypeList(find_type('content[].type'))},

I upgraded from Select2 4.0.6 to 4.0.13 but not better.
I am using Editor 1.9.2

Any suggestions ?
Thanks in advance

SearchPanes with nested elements

$
0
0

Hi

I am trying to use searchpanes on a number of tables on our site and ran into a problem where the <td> element has a nested element (eg. span, div, a) within it.

In these cases, instead of displaying the cell value with a corresponding row count, the searchPane only displays the count. Where the nested element is an anchor/href, the count is also hyperlinked.

I have reworked my pages to avoid using a nested elements (span, div etc) within the <td> elements and although not ideal. this works fine.

However where the table entry needs to be a link (e.g. click on customer name in table to link to customer details page), a nested <a href=...> tag is unavoidable.

I have created a demo. The html is updated so that entries where office is "Edinburgh" it is a hyperlink.
http://live.datatables.net/bofeyosi/1/

Assuming this is unavoidable, is there a workaround to ignore the the href element and just use the cell value?

paging not show correct total entries

$
0
0

My data have 12 record but datatable just display 10 entries. Although I have entered more data, it still displays the total record as "Showing 1 to 10 of 10 entries"

How to modify oLanguage.sInfo

$
0
0
 "bInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",

How to print or convert to PDF from datatables column images

$
0
0

I want to export a datatables in format like

-------------------------------------------------
sr | id  | name |  phone     |  photo
-------------------------------------------------
1  | s12 | John | 9874563210 | Image 
-------------------------------------------------

HTML code:

<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
 <tr>
  <th>Sr. No</th>
  <th>id</th>
  <th>Name</th>
  <th>Phone Number</th>
  <th>Photo</th>
 </tr>
</thead>
<tbody>
<?php 
$sr=0;
$sql = "SELECT * FROM `user` ORDER BY `name ASC ";
$result = mysqli_query ($connect, $SQL);
if (mysqli_num_rows ($result) > 0) {
while ($fieldinfo=mysqli_fetch_object ($result)
{
 $sid=$fieldinfo->sid;
 $name=$fieldinfo->name;
 $phone=$fieldinfo->phone;
 $photo = $fieldinfo->photo;
 $sr=$sr+1;
?>
 <tr>
  <td><?PHP echo $sr?></td>
  <td><?PHP echo $sid?></td>
  <td><?PHP echo $name?></td>
  <td><?PHP echo $phone?></td>
  <td><img src="upload/photo/<?PHP echo $photo;?>" onError="this.onerror=null;this.src='images/placeholder.png';" style="height: 80px;"></td>
 </tr>
<?PHP }?>
</tbody>
</table>

If photo is not available then onError="this.onerror=null; will display placeholder.

My JavaScript code is:

    <script>
        $('#example23').DataTable({
            dom: 'Bfrtip',
            buttons: [
                {
                  extend: 'copy',
                  title: 'Result for copy'
                },  
                {
                  extend: 'excel',
                  title: 'Result for excel'
                }, 
                {
                  extend: 'pdf',
                  title: 'Result for pdf'
                }, 
                {
                  extend: 'print',
                  title: 'Result for Print'
                }
            ],
            "pageLength": 50,
            "oLanguage": {
              "sSearch": "Quick Search / Sorting: "
            }
        });

        </script>

When I export my table, the photo column remains empty. But images are displaying in datatables. I want to display all images in my exported file (PDF).

Viewing all 82141 articles
Browse latest View live


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