Quantcast
Channel: Free community support — DataTables forums
Viewing all 35273 articles
Browse latest View live

Adding request.GET parameters to server side request

$
0
0

I'm trying to create a page which contains a form for searching the database (for events) as well as a list of the relevant events found.

I'm using server side processing to limit the load on each request but, since the call to the URL for the server side events is a separate HTTP request, the parameters used when someone submits the form aren't passed through to the server so I always get all events, regardless of the filtering done by the form.

The URL of the page (after the search form has been submitted) is:-

/events/?from_date=22%2F09%2F2016

I then create the datatable like this (to try and pass the GET parameters from the search into the server for processing):-

ajax: {
url: "{% url 'event_list' %}",
data: function (d) {
d.filters = "{{ request.GET|safe }}";
}
}

But that doesn't seem to work.

Is there a better way or am I on the right track and just need to make some small adjustment somewhere?


very simple q: how to store database id in rows/records?

$
0
0

Hi all, I am sure this is possible with datatables' rich API, but actually cannot find the answer in the docs or examples :(
I have a column with database primary key (ID). I want to store it for later web api usage, but do not want to display it to the user. What is the easiest way to do this?

How to set column width for DataTables?

$
0
0

I want to set static width for all DataTables (with scroll plugin) columns.

It makes the columns wider if I set width for all <th> tags except one. And it doesn't work if the width is set for all tags. Plus, when I inspect via the developer tools, I don't see any <th> element with width 400px. The elements have different width: 115px, 132px, 145px ...
Why is that? How can I set the exact width for columns?

CSS

.big-col {
  width: 400px;
}

JS

var options = {
    "sScrollX": "100%",
    "sScrollXInner": "110%",
    "bScrollCollapse": true,
    "colReorder": true
};

$(document).ready(function() {
    $('#example').dataTable(options);
});

Full example: http://fiddle.jshell.net/sergibondarenko/o1hoabep/8/

Also, I tried the columnDefs option, without success.

 var options = {
    "columnDefs": [
      { "width": "100px", "targets": "_all" }
    ]
 };

The exact number of columns is unknown. The HTML table is built dynamically based on data from a server side.

Related question on StackOverflow: http://stackoverflow.com/questions/39771968/how-to-set-column-width-for-datatables

How to count the json data before loading the datables

$
0
0

Hi ,
How to count the records in datatables before loading . Below is my datatables

var Table;
function displayDataTable() {
Table= $('#example').DataTable(
{
"ajax": {
"url": '@Url.Action("Search", "Home")',
"dataSrc": "",
"dataType": "json",
},
"dom": '<"row"<"col-xs-6"f><"col-xs-6 text-right toolbar">>rt<"row"<i><l><"col-xs-12"p>>',
"pagingType": "simple_numbers",

"columns": [

{ "data": "CashId" },
{ "data": "PaymentType" },
{ "data": "Amount" },
{ "data": "PhoneNumber" },
{ "data": "Name" },
],
"columnDefs": [

            { orderable: false, targets: 5 }
    ],         
    "order": [[1, 'desc']],
});

}

How to pass an Ajax URL with params inside a ajax.url() method?

$
0
0

Hi guys,

I'm trying to change the url of an existing table and load it. How can I pass params in this ajax.url method?

I wanna do somethig like this:

var oTable;

$(function(){
        
        oTable = $('.sortable').DataTable({
            bRetrieve: true,
            bProcessing: true,
                    bServerSide: true,
                   ajax: 'my_url.php',
                   sPaginationType: 'full_numbers',
            
            });

        $("#my_checkbox").change(function(){
             //Wanna use my new url and params here 
                     contratosTable.ajax.url(new_url, params).load();
        }); 
});

Thanks for attention!

Trouble with data Ajax call

$
0
0

Hello,
I am trying to bind a datatable to data acquired via an ajax call, but the ajax call always returns an empty array.
However, a direct call to the data with a jquery ajax call returns the data successfully.

Here is my code:

<html>
    <head>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
        <script src="//code.jquery.com/jquery-1.12.3.js"></script>
        <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
        <script>

            var jsonData;
            $.ajax({
                url: "https://api.domain.com/group/",
                type: 'GET',
                success: function(data, textStatus, jqXHR)
                {
                    console.log(data); //*** returns correct json data
                }
            });

            $(document).ready(function() {
                $('#example').DataTable( {
                    "ajax": {
                        "url": "https://api.domain.com/group/",
                        "type": "GET",
                        "dataSrc":"",
                        "complete": function(xhr, responseText){
                            console.log(xhr);
                            console.log(responseText); //*** responseJSON: Array[0]
                        }
                    }
                } );
            } );

        </script>
    </head>
    <body>
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>name</th>
                    <th>description</th>
                    <th>createdAt</th>
                    <th>updatedAt</th>
                    <th>id</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>name</th>
                    <th>description</th>
                    <th>createdAt</th>
                    <th>updatedAt</th>
                    <th>id</th>
                </tr>
            </tfoot>
        </table>
    </body>
</html>

Here is the json returned by the jquery ajax call:

[
  {
    "experiments": [
      {
        "name": "Animation",
        "description": "test",
        "group": 1,
        "createdAt": "2015-10-22T02:10:53.691Z",
        "updatedAt": "2015-11-08T03:41:08.173Z",
        "id": 2,
        "build_number": "1.a.0032",
        "url": "experiments/svg/saves.svg"
      },
      {
        "name": "Technical Drawing",
        "description": "test",
        "group": 1,
        "createdAt": "2015-10-31T22:39:31.374Z",
        "updatedAt": "2015-11-08T04:05:46.258Z",
        "id": 3,
        "build_number": "1.a.0033",
        "url": "experiments/svg/vacumatic.svg"
      },
      {
        "name": "KeySpline Animation",
        "description": "test",
        "group": 1,
        "url": "experiments/svg/escapement.html",
        "build_number": "1.a.0034",
        "createdAt": "2015-11-08T04:09:56.049Z",
        "updatedAt": "2015-11-08T04:09:56.049Z",
        "id": 4
      }
    ],
    "name": "SVG (Scalable Vector Graphics)",
    "description": "SVG animation tests.",
    "createdAt": "2015-10-22T02:05:02.156Z",
    "updatedAt": "2015-11-08T03:08:32.662Z",
    "id": 1
  },
  {
    "experiments": [
      {
        "name": "Sails JS",
        "description": "Building a restful api with Sails JS",
        "group": 2,
        "url": "https://api.jptrue.com",
        "build_number": "1.a.0035",
        "createdAt": "2015-11-10T03:04:31.383Z",
        "updatedAt": "2015-11-10T03:22:03.192Z",
        "id": 6
      }
    ],
    "name": "API (Application Program Interface)",
    "description": "API tests.",
    "createdAt": "2015-10-22T02:06:55.339Z",
    "updatedAt": "2015-11-08T03:09:39.163Z",
    "id": 2
  },
  {
    "experiments": [
      {
        "name": "Dynamically generated alerts",
        "description": "test",
        "group": 3,
        "url": "experiments/bootstrap/alert.html",
        "build_number": "1.a.0035",
        "createdAt": "2015-11-08T04:40:56.812Z",
        "updatedAt": "2015-11-08T04:40:56.812Z",
        "id": 5
      }
    ],
    "name": "Bootstrap",
    "description": "Scalable Vector Graphics",
    "createdAt": "2015-10-31T22:38:50.180Z",
    "updatedAt": "2015-11-08T04:39:37.239Z",
    "id": 3
  }
]

Any help is greatly appreciated!

Thanks,
Jeff

Does datatables will accept alert function?But i found it not works?

$
0
0

I had used the following part of code to display popup?Is anything i missed or i want add in the following alert part?

print "\$(\'#placeholder28-table tbody tr\').on(\'click\',\'td:nt-child(10)\',function(f){ ^M \n";
alert('Data:'+$(this).html().child());
alert('Row:'+$(this).parent().find('td').html().child());
alert('Column:'+$('#placeholder thead tr th').eq($(this).index()).html().child());
print "});\n";
print "});\n";

Data exists in the table, but the table displays ' no data available in table'

$
0
0

https://debug.datatables.net/esumox

While updating the checkboxes in column 1, very rarely all the data completely disappears and nets me 'No data available in table' message, which is strange because its not even my set message.

"oLanguage": { "emptyTable": "No data available in table, try changing your options or refresh your browser if the problem continues.", "sEmptyTable": "No data available in table, try changing your options or refresh your browser if the problem continues." }

What scenario would it bypass this and go back to the default? I'm not familiar with dataTables enough to understand what causes this issue.

looking at the debug log, the data is in there, yet the full table state notes the table's are empty?

Any help would be appreciated.


Script Support for Small Screens

How to join a table on two conditions?

$
0
0

I see that the leftJoin function takes the four parameters:

leftJoin( 'view_data_points', 'data_reporting_manual.data_point_id', '=', 'view_data_points.data_point_id' )

This can produce something like:

INNER JOIN data_reporting_manual ON data_reporting_manual.data_point_id = view_data_points.data_point_id

However what I'm trying to do is that last JOIN with the AND. How can I do this?

SELECT
view_data_points.short_name,
view_data_points.data_point_id,
data_reporting_manual.data_date,
data_reporting_manual.data_value,
data_reporting.data_value as SFValue
FROM
view_data_points
INNER JOIN data_reporting_manual ON data_reporting_manual.data_point_id = view_data_points.data_point_id
INNER JOIN data_reporting ON data_reporting_manual.data_point_id = data_reporting.data_point_id AND data_reporting_manual.data_date = data_reporting.data_date

What I've tried is the following code in my ajax.php. Notice the comment //breaks to see the join that breaks things:

Editor::inst( $db, 'data_reporting_manual' )
      ->pkey( 'data_reporting_manual.data_id' )
      ->field(
          Field::inst( 'data_reporting_manual.data_date' )->validator( 'Validate::dateFormat', array(
              "format"  => Format::DATE_ISO_8601,
              "message" => "Please enter a date in the format yyyy-mm-dd"
          ) )
               ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
               ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
          Field::inst( 'data_reporting_manual.data_value' ),
          Field::inst( 'view_data_points.short_name' ),
          Field::inst( 'data_reporting_manual.data_point_id' )
               ->options( 'view_data_points', 'data_point_id', 'short_name' )
      )
      ->leftJoin( 'view_data_points', 'data_reporting_manual.data_point_id', '=', 'view_data_points.data_point_id' )
    //breaks  
      ->join(
        Editor\Join::inst( 'data_reporting', 'object' )->link( 'data_reporting_manual.data_point_id', 'data_reporting.data_point_id' )->link( 'data_reporting_manual.data_date', 'data_reporting.data_date' )->field(
            Field::inst( 'data_reporting.data_value' )->set( false )->name( 'sf_data_value' )
        )
    )
      ->process( $_POST )
      ->json();

Bug in caption support?

$
0
0

It seems like adding caption-side: bottom; to a <caption> element results in the caption being between the header and the body of the table instead of below the table.

https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.constructor.js#L390 suggests that putting the CSS on the <table> tag instead of the <caption> tag fixes everything, but https://www.w3.org/TR/CSS2/tables.html#caption-position suggests it is supposed to go on the <caption> tag.

https://jsfiddle.net/pkv3u8oc/1/ demonstrates the issue.

Array as value in Editor -> options

$
0
0

I have this:

Field::inst( 'valabilitate' ) ->options( 'tarife', array('tconcesiune', 'zconcesiune'), array('tconcesiune', 'zconcesiune') 

The label is corectly taken but the value i cant take as an array.
<b>Warning</b>: Illegal offset type in.....

this works:

Field::inst( 'valabilitate' ) ->options( 'tarife','tconcesiune', array('tconcesiune', 'zconcesiune') 

but this way i cant take the value also as an array.

I just need the value to be the same as the label.

Any suggestions or help is much apreciated!

columns.render hyperlink

$
0
0

Hi! I'm okay creating hyperlinks using:

"columnDefs": [ {
            "targets": 3,
            "render": function ( data, type, full, meta ) {
                return '<a href=\"docs/resolutions/'+data+'\" target=\"_blank\">PDF</a>';
                }
         } ]

"+data+" inserts the file name. But how would I insert the contents of a database column where the hyperlink text -- "PDF" -- is now? For example, "+data+" is the filename and I want to insert the document title, from the database instead of the static "PDF" text.

If the examples on the columns.render page explains this, I just don't understand it.

how can i activate show all in length menu for server-side processing

$
0
0

Hi,

How can the length menu be changed from 10,25,50,100 to 10,25,50,100 and all?#
I am doing serverside processing and i tried the -1 in lengthmenu - no luck.
Please help me
Thanks in advance

How to export all data of parent table contain pagination

$
0
0

When my page loading, It will load parent table with pagination (50item/page). When I click button with DataTable function and export data. child table just show 50item on page 1 of parent table and just export 50 item
Please help me !


rows.add() with javascript Json

$
0
0

Hello, I'm trying to load data from a javascript generate json object. Unfortunately, nothing happens and data is not loaded.
If the json data is added into a file and used via the ajax call, then the data is loaded just fine.

javascript:

modul='123';
var text='{"data" : [' +
 '{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12"},' +
 '{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12"}]}';
var data = JSON.parse(text);

console.log(jQuery('#'+modul).DataTable().rows.add(data).draw());

I have set the columns definition:

"columns": [
                    { "data": "param1"},
                    { "data": "param2"},
                    { "data": "param3"},
                    { "data": "param4"}
        ],          

Working object.txt with: "ajax": "/objects.txt",

{"data":[
    {"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12"},
    {"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12"}]}

The data is obviously parsed. I got some index mismatches before. All that is resolved..

Here is the example: http://live.datatables.net/gureleve/1

What am I missing??

Thanks

How can I get my +- buttons working on all pages?

$
0
0

I have a basic table, but with +- buttons:

            <tbody>
                @foreach (var item in Model.Stock)
                {
                    <tr>
                        @Html.HiddenFor(modelItem => item.Id)
                        @Html.HiddenFor(modelItem => item.StockCode)
                        @Html.HiddenFor(modelItem => item.AnotherChecked)
                        <td>
                            @Html.DisplayFor(modelItem => item.Description)
                        </td>
                        <td>
                            <button type="button" class="buttonM">&dArr;</button>
                            @Html.TextBoxFor(modelItem => item.NewQty, new { id = "newQty", name = "newQtyN", type = "number", min = "0", max = "1000", style = "width:50px" })
                            <button type="button" class="buttonP">&uArr;</button>
                        </td>

                        <td>
                            @Html.CheckBoxFor(modelItem => item.Checked, new { id = "checked" })

                        </td>
                    </tr>
                }
            </tbody>

the code that USED (before dataTables) to work fine for +- is

            $(".buttonM").on("click", function () {

                var myT = document.getElementById('stockTable');
                var $row = $(this).parents('tr:first');
                var newVal=Number( $row.find('#newQty').val())-1;
                if (newVal>=0)
                    var sel = $row.find('#newQty').val(newVal);

            });
            $(".buttonP").on("click", function () {
                var myT = document.getElementById('stockTable');
                var $row = $(this).parents('tr:first');
                var newVal = Number( $row.find('#newQty').val())+1 ;
                if (newVal >= 0)
                    var sel = $row.find('#newQty').val(newVal);
            });

now it only works on the first page - can anyone point me to the solution?

Sorting and Searching doesnt not work,although my table load data fine

$
0
0

I am using Jquery Datatables plugin....the table loaded perfectly fine with all the data but sorting and searching does not work,i have tried to google all around for almost two days but no luck at all.When i click ascending and descending arrows,nothing happens on my columns.And when i try to search anything on my table search box it says 'No matching Found' even though i can see a data i am trying to search.I am using:-

Datatables version 1.10.12

Here is JSfiddle code:- https://jsfiddle.net/udy2ysnv/

Below is my JSfiddle showing the problem:- https://jsfiddle.net/udy2ysnv/

ScrollY and Alphabet input search

$
0
0

HI

Can both 'ScrollY' and 'Alphabet input search' input search be used on the same datatable ?

Cheers

Datatable Ajax Url Parameter

$
0
0

Hello,

I am having an issue binding data to a datatable when passing in the url to an ajax call.

When running the following code databable 'example' throws this alert twice:
** DataTables warning: table id=example - Requested unknown parameter '0' for row 0, column 0.**

However, if i pass the data directly to the ajax call for datatable 'example2', it works great.

Here is some code that shows a working and non-working example:

JAVASCRIPT

            // NOT WORKING
            // DataTables warning: table id=example - Requested unknown parameter '0' for row 0, column 0.
            $(document).ready(function() {
                $('#example').dataTable( {
                    "ajax": {
                        "url": "json.data",
                        "type": "GET",
                        "cache": true,
                        "columns": [
                            { "data": "id" },
                            { "data": "name" },
                            { "data": "description" },
                            { "data": "createdAt" },
                            { "data": "updatedAt" }
                        ],
                        "complete": function(xhr, status){
                            console.log(xhr.responseText);
                            console.log(status);
                        }
                    }
                } );

                // THIS IS WORKING GREAT
                $('#example2').DataTable( {
                    "ajax": "json.data",
                    "columns": [
                        { "data": "id" },
                        { "data": "name" },
                        { "data": "description" },
                        { "data": "createdAt" },
                        { "data": "updatedAt" }
                    ]
                } );
            } );

HTML

    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>Description</th>
                <th>Created</th>
                <th>Updated</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>Description</th>
                <th>Created</th>
                <th>Updated</th>
            </tr>
        </tfoot>
    </table>
    <table id="example2" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>Description</th>
                <th>Created</th>
                <th>Updated</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>id</th>
                <th>Name</th>
                <th>Description</th>
                <th>Created</th>
                <th>Updated</th>
            </tr>
        </tfoot>
    </table>

JSON

{
"data":[
  {
    "experiments": [
      {
        "name": "Animation",
        "description": "test",
        "group": 1,
        "createdAt": "2015-10-22T02:10:53.691Z",
        "updatedAt": "2015-11-08T03:41:08.173Z",
        "id": 2,
        "build_number": "1.a.0032",
        "url": "experiments/svg/saves.svg"
      },
      {
        "name": "Technical Drawing",
        "description": "test",
        "group": 1,
        "createdAt": "2015-10-31T22:39:31.374Z",
        "updatedAt": "2015-11-08T04:05:46.258Z",
        "id": 3,
        "build_number": "1.a.0033",
        "url": "experiments/svg/vacumatic.svg"
      },
      {
        "name": "KeySpline Animation",
        "description": "test",
        "group": 1,
        "url": "experiments/svg/escapement.html",
        "build_number": "1.a.0034",
        "createdAt": "2015-11-08T04:09:56.049Z",
        "updatedAt": "2015-11-08T04:09:56.049Z",
        "id": 4
      }
    ],
    "name": "SVG (Scalable Vector Graphics)",
    "description": "SVG animation tests.",
    "createdAt": "2015-10-22T02:05:02.156Z",
    "updatedAt": "2015-11-08T03:08:32.662Z",
    "id": 1
  },
  {
    "experiments": [
      {
        "name": "Sails JS",
        "description": "Building a restful api with Sails JS",
        "group": 2,
        "url": "https://api.jptrue.com",
        "build_number": "1.a.0035",
        "createdAt": "2015-11-10T03:04:31.383Z",
        "updatedAt": "2015-11-10T03:22:03.192Z",
        "id": 6
      }
    ],
    "name": "API (Application Program Interface)",
    "description": "API tests.",
    "createdAt": "2015-10-22T02:06:55.339Z",
    "updatedAt": "2015-11-08T03:09:39.163Z",
    "id": 2
  },
  {
    "experiments": [
      {
        "name": "Dynamically generated alerts",
        "description": "test",
        "group": 3,
        "url": "experiments/bootstrap/alert.html",
        "build_number": "1.a.0035",
        "createdAt": "2015-11-08T04:40:56.812Z",
        "updatedAt": "2015-11-08T04:40:56.812Z",
        "id": 5
      }
    ],
    "name": "Bootstrap",
    "description": "Scalable Vector Graphics",
    "createdAt": "2015-10-31T22:38:50.180Z",
    "updatedAt": "2015-11-08T04:39:37.239Z",
    "id": 3
  }
]
}

Any ideas on fixing this issue are greatly appreciated.

Thanks,
Jeff

Viewing all 35273 articles
Browse latest View live