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

Need help Row details dont work properly

$
0
0

hi

to start sorry if my english is not very good I'm french.

I do not know how to explain that.

I put in my datatable row details ( https://datatables.net/examples/server_side/row_details.html ), but it does not work properly.

in the beginning everything works, on all the lines of my table.
when I change the category (ex: PUBG) it works, I can open row detail for my 3 lines, but when I put back without category (all games), only the first 3 lines work, I can not open row detail for others.

I dont understand why it does not work after.

someone can help me ?

my website : http://ckdn.esy.es/

table page html:

                  <table id="product_data" class="">
                     <thead>
                        <tr>
                            <th  style="width: 28px;" ></th>
                             <th><i class="far fa-calendar-alt"></i></th>
                             <th><i class="far fa-user"></i></th>
                           <th><i class="far fa-gamepad"></i>
                              <select name="category" id="category" class="form-control">
                                   <option value="">Touts les Jeux</option>
                                   {$envoie} <!-- reçoit la boucle php  -->
                              </select>
                           </th>
                            <th>Age</th>
                        </tr>
                     </thead>
                  </table>

script page html

         <script type="text/javascript" language="javascript" >
  $(document).ready(function (){

   load_data();

   function load_data(is_category)
   {
    var dataTable = $('#product_data').DataTable({
     "processing":true,
     "serverSide":true,
     "order":[],
     "ajax":{
      url:"includes/fetch.php",
      type:"POST",
      data:{is_category:is_category}
     },
     "columns": [
              {
                  "className":      'details-control',
                  "orderable":      false,
                  "data":           null,
                  "defaultContent": ''
              },
              { "data": 1},
              { "data": 2},
              { "data": 3,
                "orderable":false,},
              { "data": 4 }
          ],
     "language": {
       "processing": "<div id='loader'></div>"
    }
    });

  // affiche plus de détaille annonce 
  function format ( d ) {
      if ( d[5] == '') {
        $online = '<div class="steamWidget no-steam">'+
                  'Statut Steam: <p>Steam Non renseigné</p><br><br>'+
                  'Description Prochainement</div>';

      } else {

        if ( d[5] == 'online') {
              $online = '<div class="steamWidget online">'+
                        'Statut Steam:<p>'+d[5]+'</p><br><br>'+
                        'Description Prochainement</div>';
            }
            else  {
                $online = '<div class="steamWidget offline">'+
                          'Statut Steam:<p>'+d[5]+'</p><br><br>'+
                          'Description Prochainement</div>'; 
            }

      }
      return $online;
  }

        // affiche plus de détaille annonce suite
      $(document).on('click', 'td.details-control', function () {
          var tr = $(this).closest('tr');
          var row = dataTable.row( tr );

          if ( row.child.isShown() ) {
              // This row is already open - close it
              row.child.hide();
              tr.removeClass('shown');
          }
          else {
              // Open this row
              row.child( format(row.data()) ).show();
              tr.addClass('shown');
          }
      } );

   }
  // change la catégorie
   $(document).on('change', '#category', function(){
    var category = $(this).val();
    $('#product_data').DataTable().destroy();
    if(category != '')
    {
     load_data(category);
    }
    else
    {
     load_data();
    }
   });
  </script>

And my fetch page:

      require_once('../includes/config.php');
          $connect = new mysqli($CONF['host'], $CONF['user'], $CONF['pass'], $CONF['name']);
          if ($connect->connect_errno) {
              echo "Failed to connect to MySQL: (" . $connect->connect_errno . ") " . $connect->connect_error;
          };

        $column = array("","date_add", "username", "category_g_name", "born");
        $query = "
         SELECT * FROM users U
         INNER JOIN users_category UC ON (U.idu = UC.id_users)
         INNER JOIN category_games C ON (UC.id_category = C.id)  
        ";
        $query .= " WHERE";
        $query .= " UC.recherche = 1 AND";
        if(isset($_POST["is_category"]))
        {
         $query .= " id = '".$_POST["is_category"]."' AND ";
        }


        if(isset($_POST["search"]["value"]))
        {
         $query .= '(date_add LIKE "%'.$_POST["search"]["value"].'%" ';
         $query .= 'OR username LIKE "%'.$_POST["search"]["value"].'%" ';
         $query .= 'OR category_g_name LIKE "%'.$_POST["search"]["value"].'%" ';
         $query .= 'OR recherche LIKE "%'.$_POST["search"]["value"].'%" ';
         $query .= 'OR born LIKE "%'.$_POST["search"]["value"].'%") ';
        }

        if(isset($_POST["order"]))
        {
         $query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
        }
        else
        {
         $query .= 'ORDER BY date_add DESC ';
        }

        $query1 = '';

        if($_POST["length"] != 1)
        {
         $query1 .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
        }


        $number_filter_row = mysqli_num_rows(mysqli_query($connect, $query));

        $result = mysqli_query($connect, $query . $query1);

        $data = array();



        while($row = mysqli_fetch_array($result))
        {   
            if (isset($row["steam"]))
                {
                    $steam = simplexml_load_file("https://steamcommunity.com/profiles/".$row["steam"]."?xml=1", 'SimpleXMLElement', LIBXML_NOCDATA);
                    $steamstatut = str_replace("<br />", " - ", $steam->onlineState);
                } else {
                    $steamstatut = '';
                }

            // calcule age user
            $ub = explode('-', $row["born"]) ;
            $age = date('Y') - $ub[0] ;
            if ( date('md') < $ub[1].$ub[2] ) $age-- ; 

            //calcul nbr de our de l'annonce
            $now = new DateTime("now");
            $dateBdd = new DateTime($row["date_add"]);
            //$date_add = $dateBdd1->diff($now)->format("%d jours, %h heurs and %i minutes");
            $date_add = $dateBdd->diff($now);
            $jours = $date_add->format("%d jrs");
            $heurs = $date_add->format("%h hrs");
            $minute = $date_add->format("%i min");
            if ($jours == 0 ) {  

                if ($heurs == 0 ) {
                    $afficher = $minute;
                }
                else {
                    $afficher = $heurs;
                }
            }  else {
                    $afficher = $jours;
            }

            $URL = $CONF['url'];
         $sub_array = array();
         $sub_array[] = '<th></th>';
         $sub_array[] = $afficher;
         $sub_array[] = $row["username"];
         $sub_array[] = $row["category_g_name"];
         $sub_array[] =  $age. 'ans';
          $sub_array[] = $steamstatut;
         $data[] = $sub_array;

        }

        function get_all_data($connect)
        {

         $query = "SELECT * FROM users_category";
         $result = mysqli_query($connect, $query);
         return mysqli_num_rows($result);
        }

        $output = array(
         "draw"    => intval($_POST["draw"]),
         "recordsTotal"  =>  get_all_data($connect),
         "recordsFiltered" => $number_filter_row,
         "data"    => $data
        );

        echo json_encode($output);

thank a lot


I am the new guy

$
0
0

Helpful content, Appreciate it!

Check out my homepage; <a href="http://www.newsifficulty.com/">簡約 手錶,寶可夢 手錶,stuhrling 手錶,手錶 手環 搭配,moment 手錶,海豹部隊 手錶,手錶 拍賣,ice 手錶,pulsar 手錶,devano 手錶,aw 手錶,exponi 手錶,longines 手錶,女 手錶,automatic 手錶,paul smith 手錶,wilon 手錶,新訓 手錶,q&q 手錶 評價,jumpy 手錶</a>

DataTables - Editor - Field Errors Summary when using a Custom Template.

$
0
0

I am using a custom template via template: '#inventoryServerForm'. Currently, I create my own field error summary like this:

            // display editor ajax errors in a modal
            editor.on('submitUnsuccessful', function (e, xhr, err, thrown, data) {

                var $formErrors = $('#formErrors');

                if (xhr != null && xhr.fieldErrors != null && xhr.fieldErrors.length) {

                    // Build summary
                    var $ul = $('<ul>');
                    for (var i = 0; i < xhr.fieldErrors.length; i++) {
                        $ul.append(`<li class="text-danger"><span>${xhr.fieldErrors[i].status}</span></li>`);
                    }
                    $formErrors.append($ul);

                    // Update form with BS4 stuff
                    // This is supposed to be fixed in 1.7.4
                    // https://datatables.net/forums/discussion/comment/131735#Comment_131735
                    $('.has-error')
                        .find('input')
                        .addClass('is-invalid');

                }
            });

I was hoping to be able to just add a placeholder for this somewhere, is there a more datatables way to do this?

Editor + KeyTable: Dropdown issues

$
0
0

I'm evaluating the Editor plugin, and have the following scenario configured, using Datatables + Editor + KeyTables.

The basic idea is to provide the users with an Excel similar experience, providing a smoth operation.

I'm having an issue with the KeyTables + Editor integration, when using a combobox field.

The Datatables + Editor + KeyTable configuration is:

    const editor = new $.fn.dataTable.Editor({
        table: "#table",
        fields: [{
                label: "Field1",
                name: "Field1"
            },
            {
                label: "Select1",
                name: "Select1",
                type: "select"
            },
            {
                label: "Select2",
                name: "Select2",
                type: "select"
            }
        ]
    });

    const table = $('#table').DataTable({
        ajax: {
            url: "api/load"
            type: "POST",
            datatype: "json",
            dataSrc: ""
            },
            keys: {
              editor:  editor,
              editOnFocus: true       
            },
            select: {
                style:    'os',
                selector: 'td:first-child',
                blurable: true
            },
            columns: [{
                data: "Field1"
            },
            {
                data: "Select1"
            },
            {
                data: "Select2"
            }
        ]
    });

    // Inline editing on tab focus
    $('#table').on('key-focus', function (e, datatable, cell) {
       editor.inline(cell.index());
    });

When the field is a dropdown (select), i'm having a few strange issues:
1. When the data is loaded, the dropdown fields are empty. Only when tabbing/clicking on the field, it shows the dropdown, and on blur, the field data is changed to the select value
2. Due to the differences between sizes, length, etc, when on the dropdown field, there are some row adjustments, and it creates a strange effect.

Is there any configuration that could mitigate the above issues? Please note that the idea is to have the smothest editing experience possible.

There are some plugins to improve the dropdown lists, as Select2 or Selectize.

Would the use of any of these plugins improve these dropdowns specific issues? And if so, can Select2/Selectize be used with the Editor plugin in the free evaluation period (15 days).

I downloaded the CSS and JS files for Select2 here, but i received the following error:
"Uncaught Error adding field - unknown field type select2" - jquery 1.12.4

exporting child table data

$
0
0

Hi,

I have a datatable that displays master data and when a row is clicked, the relevant detail data is diplayed by adding new rows to the master data table example master table woulddisplay order information and when clicking on the an order row, a new row below it would display additional rows containing line item information.

I am doing this by storing the child data rows as hidden data in the main datatable column and showing it in new row when the row is clicked.

Will it be possible to export this child rows using the export pdf/excel functionality of the data table? The printscreen shows the data correctly, however , the pdf export functionality shows the child data (in the hidden column) which is not correctly formated. Ideally it should be below the main mater table row.

if there are any other approaches this functionality , kindly let me know.

Thanks, Julio

Sorting Datetime removes all other functionality of datatable

$
0
0

On trying to add the Ultimate date / time sorting plugin, I'm able to sort the date but all the other features of data table like sorting,search, pagination goes away.

I've done the following:
Added moment.js to my page
Added datetime-moment.js to my page.


$(document).ready(function () { $.fn.dataTable.moment('D/M/YYYY h:mm:ss A'); $('#OnProcess').dataTable({ language: { sZeroRecords: 'لا توجد سجلات مطابقة', sEmptyTable: 'لا توجد البيانات', search: "_INPUT_", searchPlaceholder: "ابحث هنا...", oPaginate: { sNext: '', sPrevious: '', } }, "aLengthMenu": [[10, 15, 20 - 1], [10, 15, 20, "All"]], "iDisplayLength": 10, "columnDefs": [{ "className": "dt-right", "targets": "_all", }], "columnDefs": [{ "targets": 2, //,"orderable": false "render": $.fn.dataTable.render.ellipsis(25, true) }] }); })

What could be the problem?

How can I put a line and space in the PDF header?

$
0
0

I put this header and I don't manage add a line and space to separate from grid:

source:

var tabExp = $('#tabelaDataTableExport').DataTable({
    //dom: '<Bf<t>ip>',

    dom: "<'row'<'col-sm-6'B><'col-sm-6'f>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-6'i><'col-sm-6'p>>",
    buttons: [ 

        {

            customize: function ( doc ) {

doc['header']=(function(page, pages) {
return {
columns: [

                        {
                            alignment: 'left',
                    image: 'logo.jpg',
                    width: 100

                            /*text: [
                                { text: page.toString(), italics: true },
                                ' / ',
                                { text: pages.toString(), italics: true }
                            ]*/
                        },
                        {
                            bold: true,
                            fontsize:'100px',
                            text:'Rlatório de Previsões',
                            alignment: 'center',
                            margin:[80,10,0,]

                        },
                        {

                            text: [
                                { text: page.toString(), italics: true },
                                ' / ',
                                { text: pages.toString(), italics: true }
                            ],

                            alignment: 'right',
                            margin:[100,10,0]
                        }



                        ],
                        alignment: 'center',
                        margin: [60, 18,80,100]



                    };
                });


          },
        }
    ],

    language: {
        url: uri_arquivo
    }

    //order: [[ 0, "asc" ]]
});

I want this to be this way for instance:

Anyone know how do it?

SharePoint 2010 REST w/Lookup - Working Example

$
0
0
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="/jQuery/REST/jquery-1.8.2.min.js"></script>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="/jQuery/REST/jquery.dataTables.css">
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="/jQuery/REST/jquery.dataTables.min.js"></script>

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("LoadPositions");
function LoadBINs() {
     
}
</script>
<script type="text/javascript">

function LoadPositions()  {
//remove alert in production
alert("Function running");

var call = $.ajax({
            
    url: "https://internalportal/_vti_bin/listdata.svc/CustomerRequests?$select=PositionNumber,Id,CreatedBy&$expand=CreatedBy",
            
    type: "GET",
        dataType: "json",
        headers: {
                Accept: "application/json;odata=verbose"
            }
       
        }); 


        call.done(function (data,textStatus, jqXHR){
            $('#htmlTable').dataTable({
                "bDestroy": true,
                "bProcessing": true,
                "aaData": data.d.results,
                "aoColumns": [
                    { "mDataProp": "PositionNumber" },
            { "mDataProp": "Id" },
                    { "mDataProp": "CreatedBy.Name" }

                ]
              });
        });
        call.fail(function (jqXHR,textStatus,errorThrown){
            alert("Error retrieving Tasks: " + jqXHR.responseText);
        });


}

</script>

//table headers must be same amount as data property fields
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="htmlTable">
<thead><th>Position Number</th><th>SharePoint List ID</th><th>Created By</th></thead>
</table>

This link was helpful to explain the difference in 2013 and 2010 $expand use: https://www.robertkaucher.com/tech/2014/2/27/expand-and-lookup-fields-in-sharepoint-2013

This was also helpful: http://www.andrewconnell.com/blog/Applying-Filters-to-Lookup-Fields-with-the-SP2013-REST-API


DataTable related issue

$
0
0

How to Resolve error stating:"d.dequeue is not a function", when trying to bind data to datatable?

DataTables rows appearing with POST requests but disappearing when sorting the columns

$
0
0

I need assistance with a weird issue. I have created a todo list app (while following an online course). The todolist works just fine. However I am trying to create a row in a table for each todo created. The rows are created without any issues, however, all the automatically created rows, although the display, they are also not in the table back-end. If I export the rows, it only exports the static row. See attached screenshot:

I am not sure where in my code I made the mistake.

HTML:

-------- UNNECESSARY CODE OMITTED--------
.
.
. 
     <div  class="tbl-header">

        <table id="table_id_1">
          <thead>
            <tr>
              <th>Task</th>
              <th>Date</th>
              <th>Priority</th>
              <th>Owner</th>
              <th>Delete</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Sample Content 1</td>
              <td>1 Jan 2018</td>
              <td>High</td>
              <td>John Smith</td>
              <td>X</td>
            </tr>
          </tbody>
        </table>
      </div>

        <script src="app.js" charset="utf-8"></script>
    </body>
.
.
.
------- END -------

Javascript:

$(document).ready(function() {
    $('#table_id_1').DataTable({
            dom: 'Bfrtip',
            buttons: [
            'copy', 'excel', 'pdf'
            ]
        });
    $.getJSON('/api/todos')
    .then(addTodos);
    $('#todoInput').keypress(function(event){
        if(event.which == 13){
            createTodo();
        }
    });

    --- UNNECESSARY CODE OMITTED ---
});

function addTodo(todo){
    var newTodo = $('<li class="task">'+todo.name + '<span>X</span></li>');
    newTodo.data('id', todo._id);
    newTodo.data('completed', todo.completed);
    if (todo.completed){
        newTodo.addClass('done');
    }
    $('.list').append(newTodo);
}

function addTodoRow(todo){
    var newTodoRow = $("<tr><td>"+todo.name+"</td><td>"+todo.created_date+"</td><td>High</td><td>Stephan Du Toit</td><td><span id='dele'>X</span></td></tr>");
    newTodoRow.data('id', todo._id);
    newTodoRow.data('completed', todo.completed);
    if (todo.completed){
        newTodoRow.addClass('done');
    }
    $('tbody').append(newTodoRow);
}

function addTodos(todos){
    //add todos to page here
    todos.forEach(function(todo){
        addTodo(todo);
        addTodoRow(todo);
    });
}

function createTodo(){
    //send request to create new todo
    var userInput = $('#todoInput').val();
    $.post('/api/todos', {name: userInput})
    .then(function(newTodo){
        $('#todoInput').val('');
        addTodo(newTodo);
        addTodoRow(newTodo);
    })
    .catch(function(err){
        console.log(err);
    });
}

--- UNNECESSARY CODE OMITTED ---

I suspect the problem is with function addTodoRow(todo).

Appreciate any assistance.

Regards
Stephan

How can I put a line and space in the PDF header?

$
0
0

I put this header and I don't manage add a line and space to separate from grid:

source:

var tabExp = $('#tabelaDataTableExport').DataTable({
    //dom: '<Bf<t>ip>',

    dom: "<'row'<'col-sm-6'B><'col-sm-6'f>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-6'i><'col-sm-6'p>>",
    buttons: [ 

        {

            customize: function ( doc ) {

doc['header']=(function(page, pages) {
return {
columns: [

                        {
                            alignment: 'left',
                    image: 'logo.jpg',
                    width: 100

                            /*text: [
                                { text: page.toString(), italics: true },
                                ' / ',
                                { text: pages.toString(), italics: true }
                            ]*/
                        },
                        {
                            bold: true,
                            fontsize:'100px',
                            text:'Rlatório de Previsões',
                            alignment: 'center',
                            margin:[80,10,0,]

                        },
                        {

                            text: [
                                { text: page.toString(), italics: true },
                                ' / ',
                                { text: pages.toString(), italics: true }
                            ],

                            alignment: 'right',
                            margin:[100,10,0]
                        }



                        ],
                        alignment: 'center',
                        margin: [60, 18,80,100]



                    };
                });


          },
        }
    ],

    language: {
        url: uri_arquivo
    }

    //order: [[ 0, "asc" ]]
});

I want this to be this way for instance:

Anyone know how do it?

DataTables and mdbootstrap.com creates bugs

$
0
0

I'm building an admin site for a customer with a lot of data, naturally I'm using datatables since it does exactly what I need.
However, since the site uses the Material Design framework from https://mdbootstrap.com/ I've run into a very annoying bug.

When I activate the "lengthChange": true (or just make a basic initialisation) I only get the text, not the select.
It's visible in the source, but not on the page, just the label text.

I've narrowed it down to a conflict with how select elements are handled in mdbootstrap css. If I remove the mdbootstrap css, all table controls works just fine, except that the whole site falls apart

First I'm wondering if anyone else has gotten the same issue, and if so, did you solve it?

If not, I've tried to add my own custom select with the same names/id's wrappers as the generated one, it shows up just fine, but then the table does not pick up the changes.

Appreciate any help/tips.

serverSide and paging problem

$
0
0

Hi
I'm using option pageLength: 20 and it works fine: At the bottom of the table it shows:
Showing 1 to 20 of 426 entries

Now I have tried to switch to server side processing, so I have added the option serverSide: true . And now, the data table shows all the 426 records on one page and at the bottom it shows:
Showing 0 to 0 of 0 entries (filtered from NaN total entries)

Is there anything I need to consider when using serverSide true regarding to paging?

Regards,
marwi

stateLoadCallback async doesn't work when multiple Datatables present

$
0
0

Since DataTables 1.10.13 we don't need to use the async: false in the ajax call from within the stateLoadCallback function. But this doesn't seems to work when you have a page with multiple Datatables in it. The error "Uncaught TypeError: Cannot read property 'parentNode' of null" will be thrown unless the option async: false is set in the $.ajax call.

Example: http://live.datatables.net/culalumo
Debug code: emomew

Is there a workaround for this? Or do we need to keep using the "old way"?

Editor 1.7.3 : error message if json_encode fails

$
0
0

HI, using Editor 1.7.3, I'm receive an error message :
{"error":"JSON encoding error: Malformed UTF-8 characters, possibly incorrectly encoded"}.

  1. How I can have mode information to debug. ?
  2. Is it possible to add something to force utf encoding if not ?

Thanks for help.
Mike


FixedHeader does not work with Ajax navigation

$
0
0

Hello ,

Recently I use the library FixedHeader in my project.

Here I am confronted a problem case using the navigation ajax the overlapping headers.

When I connect everything goes well in the first grid the header is well fixed as shown in the screenshot
.

When I navigate (Ajax) to a second page and scroll down the header of the grids is also displayed that of the other grid as shown in the screenshot

How to solve this problem?

set page length and turn off pagination

$
0
0

Hello,

I want to set the pagelenght to 10 rows, but I also want to turn off pagination. This is an intro table. The full data set is displayed on a second page. I have the options set as below. It seems I can have either, no paging or set a pagelenght, but not bith

"paging": false, "pageLength": 10,

Issues using inline editor

$
0
0

Hello and thanks to everyone evolved in this great project. However i do have one problem that I am not sure how to tackle.

I am using ajax to populate the datatable from the server. I am also using inline editing to edit the data. The inline editing opens up, my select appears. NOW if I select out of the datatable then onblur triggers, server receives the data and returns the updated record and all is great.

However if a user is editing a field and then clicks another editable field I have issues. Onblur still triggers it receives the new record back and then does a redraw of the datatable. While this is happening it also tries to create a new inline editor for the newly selected field which fails because the datatable is currently being re drawn.

This means that the processing popup that appears never goes away or if I disable that then some very weird stuff happens that messes with my data integrity.

It seems then are a couple of ways to handle this:

  1. Do not trigger a new inline editor if a field is currently being edited or datatable being redrawn
  2. Don't redraw the datatable but then I still have to redraw the edited row with the new data.

What is the recommended approach to handle this. Many thanks!

''''
$('#TableScore').on('click', 'tbody td:not(:first-child)', function (e) {
//need to not trigger inline if inline is already activated
editorScore.inline(this, { onBlur: 'submit' });
});

Dynamically set className of a column

$
0
0

I am trying to hide and show columns without removing it from DOM.
So far, I am able to hide columns first in DataTable initialization. But, I am not able to show columns back via Javascript. Here is what I am trying:

//-- here oTable refers to DataTable. Code is trying to show 5th column by setting a css class that has display: block style
oTable.column(5).className = "show_column";

But, this is not working. Anybody can help?

Datatable overflow

$
0
0

Hello everyone,

How could i fix this overflow on this table?
I have

<

div class="box-content" style="overflow: scroll;">

When i display 100 rows, the column overflow.

Here a screenshot:

Thank you,

Nico

Viewing all 82203 articles
Browse latest View live


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