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

DataTable ssp.class.php

$
0
0

I asked this on StackOverflow, but it might be better to ask here since this is the DataTables home forum. I hope this makes sense.

Simply listing the contents of a MySQL table in DataTables, using server side-processing (ssp.class.php) is no problem at all. Works like a charm and I want to stress the fact that this does not concern the function "ShippingMethod" nor how to use regular DataTables in general.

I want to have a column in the DataTable that does NOT have a corresponding column in the MySQL table, and I want to populate this column with computed values, that take other column values from the MySQL table as parameters, how do I do?

MySQL table:
Contains three columns. As you can see, there is NO column here for Shipping Method.

Name | PartnerID | Express
Abe  | 23        | true
Eve  | 47        | false
Joe  | 47        | true

Pseudo-PHP function:
Returns a text-string containing shipping method, like "Plane", "Train" or "Automobile"

function ShippingMethod(PartnerID,Express) {
  return $computedDataTextString
}

HTML DataTable:
As you can see, the column Shipping Method here does not correspond to any column in the MySQL table.

<thead>
  <th>First Name</th>
  <th>Shipping Method</th>
</thead>

Prepping data for ssp.class.php
This is where I run into trouble. How do I get the results of the PHP-function (i.e. Shipping Method) in here? And how would I go about prepping the array, since there is no table column for this data?

$columns = array(
  array( 'db' => 'Name', 'dt' => 0 ), 
  array( 'db' => ???????, 'dt' => 1,

Sharepoint Online using cdn datatables - How to fix cannot perform Deep Copy() error.

$
0
0

Hi everyone,

I am using cdn datatables and I am receiving an error. The error message says

"Uncaught Error: Cannot perform DeepCopy() because a circular reference was encountered, object: [object Object], property: 0"

The process is I am getting the data in a sharepoint online through json.

Any reply would be so much appreciated.
Thanks

-caloy

add processing icon for button

$
0
0

when we click create button how to show processing icon there

I got an error while using "submit onblur " by inline editor.

$
0
0

The error shows like below,
dataTables.editor.min.js:10 Uncaught TypeError: extender is not a function
at Object.<anonymous> (dataTables.editor.min.js:10)
at Function.each (jquery-1.10.2.min.js:4)

at Editor.(anonymous function).(anonymous function) [as _submitTable] (/projectName/resource/js/dataTables.editor.min.js:10:129324)
at Editor.(anonymous function).(anonymous function) [as _submit] (projectName/resource/js/dataTables.editor.min.js:10:128077)
at dataTables.editor.min.js:10
at Editor.(anonymous function).(anonymous function) [as _event] (projectName/resource/js/dataTables.editor.min.js:10:114496)
at send (dataTables.editor.min.js:10)
at Editor.(anonymous function).(anonymous function) [as submit] (projectNameresource/js/dataTables.editor.min.js:10:88445)
at Editor.(anonymous function).(anonymous function) [as _blur] (projectName/resource/js/dataTables.editor.min.js:10:108311)
at Editor.(anonymous function).(anonymous function) [as blur] (projectName/resource/js/dataTables.editor.min.js:10:64486).

Editor initialize as,
editor = new $.fn.dataTable.Editor({
table: "#ratesDataTable",
idSrc: 'rateRowId',
fields: [ {
name: "electionId"
}]});

Activate inline editing as,
$('#rateDataTable').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
onBlur: 'submit'
} );
} );

Thanks in advance.

Uncaught TypeError on Submit onblur using inline editor

$
0
0

The error shows as below,
dataTables.editor.min.js:10 Uncaught TypeError: extender is not a function
at Object.<anonymous> (dataTables.editor.min.js:10)
at Function.each (jquery-1.10.2.min.js:4)
at Editor.(anonymous function).(anonymous function) [as _submitTable] (/projectName/resource/js/dataTables.editor.min.js:10:129324)
at Editor.(anonymous function).(anonymous function) [as _submit] (projectName/resource/js/dataTables.editor.min.js:10:128077)
at dataTables.editor.min.js:10
at Editor.(anonymous function).(anonymous function) [as _event] (projectName/resource/js/dataTables.editor.min.js:10:114496)
at send (dataTables.editor.min.js:10)
at Editor.(anonymous function).(anonymous function) [as submit] (projectNameresource/js/dataTables.editor.min.js:10:88445)
at Editor.(anonymous function).(anonymous function) [as _blur] (projectName/resource/js/dataTables.editor.min.js:10:108311)
at Editor.(anonymous function).(anonymous function) [as blur] (projectName/resource/js/dataTables.editor.min.js:10:64486).

Editor initialize as,
editor = new $.fn.dataTable.Editor({
table: "#ratesDataTable",
idSrc: 'rateRowId',
fields: [ {
name: "electionId"
}]});

Activate inline editing as,
$('#rateDataTable').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
onBlur: 'submit'
} );
} );

Thanks in advance.

Datatables PDF export - How to order for fix export ?

$
0
0

Hello,

I have two button PDF.
The first to export the table (with the sorting the user want) and an other one to export data with a specific order.

The problem is : how can i order data (asc or desc) just for one button ? I don't want to export data with basic order or the user order choice but with my own order.

example : the table is order like this at the beginning :

                            >  var table = $('#example1').DataTable( {

"scrollX": true,
"responsive": false,
"order": [[0,"desc"]],
autoWidth: true,
dom: 'lf<"floatright"B>rtip',
buttons: [
{
extend: 'pdfHtml5',
text: 'PDF',
orientation: 'landscape',
title: 'Trials',
},
{
second pdf button...
}
....

Is it possible to specify in the button a special order like : "order": [[0,"desc"]], ?

Width of column is higher than specified

$
0
0

Hi. I've installed datatables with responsive plugin in my website (v1.10.18) and for some reason the columns are being forced to collapse even though there is plenty space for them. The table contains 3 columns with very short content but no matter how wide the table is, only 2 columns are being displayed. I used the inspector to....well, inspect and I see columns have been given a width which seems to be correct but the actual width of the column is higher than specified width (check screenshot)

I created a test case but it came out fine: http://live.datatables.net/kosujaka/1/edit
Can anyone suggest what might be causing this?

Issue with Disappearing “Outline” attribute on Table Row

$
0
0

Hello there

I have a strange issue with a disappearing “outline” property on a table row. I appreciate this may not be a jquery datatables issue, however I have posted it in case it is, or if anybody here happens to have come across it before, or could recommend an appropriate forum.

I have a table where the currently selected row (“tr” element) is assigned the class “SigMania_row_highlight_style” to display a purple border around the entire row:

.SigMania_row_highlight_style {
 outline: #6300AB 1px solid;
}

<tr class="SigMania_row_highlight_style odd" role="row">

The JQuery Datatables plug in adds the “odd” class and the role.

When the user hovers over another row, I dynamically add the class “SigMania-menu-popup-hover” to the other row:

    $("tr").hover(
        function () {
            $(this).addClass(sRowHoverStyle);
        },
        function () {
            $(this).removeClass(sRowHoverStyle);
        }
    );

.SigMania-menu-popup-hover {
   background-color: #F0E9F5 !important;
}

I am taking no action on the currently selected row.

When I do this, the purple outline disappears for reasons unknown. The Html for the row is not changed – I can verify this from developer tools. Moreover, I can refresh the display (for example by just unsetting and then setting back on any property of the row from developer tools), and the outline comes back.

I am fairly sure this is an issue with Internet Explorer (I get the same issue with all versions of IE and Edge, but not in FireFox). I don’t get the same issue when I use the same technique on a user list.

Any help greatly appreciated.


Hiding element in row details (Server-side)

$
0
0

Hi, I have implemented this Ajax loaded row details https://datatables.net/blog/2017-03-31.
I would like to hide part of the row details and unhide it after click on a button. I tried to create function and add the button in the rows detail, but it's not working properly.

When I click on the button, it hides the div element I want, but when I open another row detail, the next button is showing/hiding the element in previous row.

This is my script:

function format (rowData) {
        var div = $('<div/>')
        .addClass( 'loading' )
        .text( 'Loading...' );

    $.ajax( {
        url: 'scripts/details.php',
        data: {
            name: rowData[0]
        },
        dataType: 'json',
        type: 'post',
        success: function ( json ) {
            console.log(json);
            var childTable = '<div id="rowdetails">';
            childTable = childTable.concat(
                '<div class="row rdstyle">' +
                '<button onclick="myFunction()">Click Me</button>' +
                '<div id="myDIV">' +
                'This is my DIV element.' +
               '</div>'
              ...
}


function myFunction() {
    var x = document.getElementById("myDIV");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
}

and also an error is raised :Uncaught TypeError: Cannot read property '0' of undefined on line 9

Thank you

'live' update of values changes focus

$
0
0

I have a table where I automatically update values based on 'live' data coming in through a websocket.

The table has around 60 rows and currently shows 10 rows per tabbed 'page'.

The scenario is I'm viewing the 3rd page of the table ( for example ), and some new live data arrives on the websocket for something on the 1st page. So my code updates the value in the table but then table view automatically changes to show the first page which isn't very good for the user who was happily viewing the 3rd page ( if that description makes any sense ! ).

the code fragment hanging off the websocket is :-

                // update the value of the DB point which has an id = 'payloadObj.pointid' 
                // the new value will be set to 'payloadObj.value'

                case "dbpointupdate":

                    var dbnewtable = $('#dbnewtable').DataTable();

                    var myID = "#" + payloadObj.pointid;  // generate the ID for the row which needs to be modified
                    var rowNode0 = dbnewtable.row(myID);
                    var rowData = dbnewtable.row( rowNode0 ).data();
                    rowData[4] = payloadObj.value;  // update with new live value
                    dbnewtable
                        .row( rowNode0 )
                        .data( rowData )
                        .draw();
                break;

I guess something I'm doing is changing focus ? so the table view changes to the page with the focused row ?
Is it the search for the row with an ID that does this ?

                    var rowNode0 = dbnewtable.row(myID);

If that is the case, is there some alternative code which won't change the focus ?

I'm new to using Datatables so I'm probably being stupid !

Gav

Button.html5: Uncaught TypeError: this.processing is not a function

$
0
0

Hi, I try to do dynamically change filename of export file and change other variable. But it seem the new release got problem inside button.html5.js. Can you rectify this thing. Here is the error image and the link of my code.JsFiddle

How to apply cell background color based on column name

$
0
0

I find a link https://jsfiddle.net/tf70z0L5/
In this, color is applied based on the value ( any one cell i.e., 'O' is available in the column then column is colored ).
But I need to apply based on the column name.

Filtering table data on a specific column when checkbox is checked

$
0
0

I have set up a datatable of which I can search through all categories (columns). For the sake of simplicity I'll be referring to a table of DHL packages which has 3 columns:
1. DHL Number
2. Package status (sent, arrived)
3. Date of pickup

on my webpage, I have a checkbox what is supposed to filter out (hide) all packages that have arrived since we should be interested about the packages in transit. And in an unchecked state it should show all packages.
Theoretically I would do a search for "sent" when the checkbox is checked. But how do I do that as js code? What I have done till now is:

dhlList.columns(1).Search('Sent').draw();

And this is my config of that table:
dhlList = $('#dhlList').DataTable({ scrollY: '60vh', autoWidth: true, searching: false, searchable: true, 'aoColumns': [ null, null, null, { "bSortable": false }, ], 'bSortable': [ null, null, null, { "bSortable": false }, ], paging: false });

Yet I get the error message that "dhlList.columns(...).Search is not a function".
What am I missing here?

Sums of several columns at the footer of a table

$
0
0

Hello,

I tried to have sums of several columns at the footer of my table. I tried differents options but without success.

I tried this : https://datatables.net/examples/advanced_init/footer_callback.html
but I can only have the total of one column.

I tried this: https://datatables.net/examples/plug-ins/api.html
I have all the column like I want with the sum of the sorting but there are buttons. Is there a solution to have this method with sum in the footer of columns?

I tried others thinks too but nothing good for what I want I'm a beginner and Javascript is very difficult for my at the moment.

Thanks for advance.

Delph

Question about using 'select2' field plugin

$
0
0

Hi,

I am trying to use 'select2' field plugin to achieve 'multi-select' dropdown box. I have the following sample JSON data:

"data": [
    {
      "DT_RowId": "row_1",
     MonthlyCost: 1000,
     MonthlyImpressions: 10000,
     Zone: [{
           Id: 1,
           name: "Zone1"
          },
         {
           id: 2,
          name: "Zone2"
          }
        ]
    },
    {
      "DT_RowId": "row_2",
      MonthlyCost: 100,
     MonthlyImpressions: 100,
     Zone: [{
           Id: 1,
           name: "Zone1"
          },
         {
           id: 2,
          name: "Zone2"
          },
          {
           id: 3,
           name: "Zone3"
          }
        ]
     
    }
]

I am trying to list zone using 'select2' field type with multi-select option. The following code does not work.

        {
            label: "DMA/Zone: ",
            name: "Zone[].id",
            "type": "select2",
            "opts": {
                "multiple": "multiple",
                "allowClear": true,
            },
        }

In addition, I may need to display zones in groups. I know you mentioned using 'children' properties. Can you give me an example? In this case, for example, I need to group 'zone1' and 'zone2' together. How do I do that?

Thank you very much for your help!

Jerry


Binding of grid is not happening properly. Please help!

$
0
0

javascript:
var fileinfo; //This is a string which gets filled by calling a ajax call.
function OnSuccess(response) {
fileinfo = response.d;
}
$('#example').DataTable({
data : fileinfo,
columns: [
{ title: "FileID" },
{ title: "RecordDetailsID" },
{ title: "ProductName" },
{ title: "HRI" },
{ title: "CheckNumber" },
{ title: "filename" },
{ title: "Recipinet_Name" },
{ title: "Mailing_Address" }
]
});

aspx page:

FileID RecordDetailsID ProductName HRI CheckNumber filename Recipinet_Name Mailing_Address
FileID RecordDetailsID ProductName HRI CheckNumber filename Recipinet_Name Mailing_Address

FixedColumns and Scroller issue

$
0
0

As far as I understand, FixedColumns and Scroller should be compatible, at least this example page says so:
https://datatables.net/extensions/scroller/examples/initialisation/fixedColumns.html

However, in our application, when I scroll horizontally, the header row has fixed columns, but the body columns are not fixed. They are scrolling like if FixedColumns would not be active.

The same problem can be triggered on the example page above by scrolling all the way down and then back up and then horizontally.

Is there a workaround?

Thanks!

Server side processing of 200 000 rows but Allowed memory size of exhausted and Invalid JSON respons

$
0
0

Hello,

I tried to use Datatable for displaying a long query of 250 000 rows with 22 columns. For that, I use server side processing, but with SSP::complex and joins table. I don't have any error in the sql query (when I test it in phpmyadmin this display well all the rows), but in my json return I have the error "Allowed memory size of 536870912 bytes exhausted ". And in my datatable "Invalid JSON response" (due to the allowed memory error ?).

I thought server side processing ask automtically the database with limit query to have only a smaller number of rows than the entire count of result.

Did I miss something or done something wrong ?

server side scripting for the postgres(psql) is not working?

$
0
0

I tried using the server side scripting code from the link https://datatables.net/examples/data_sources/server_side
this code works only for the mysql, it does not work for postgres database.
Is there any other sample code which supports the postgres database?
ssp.class file which is must for server-side scripting would be much appreciated if someone can share me the one.
Thanks
Koka

Print/Export Footer

$
0
0

Hello!

I've been trying to figure out how to attach the footer of my table when I print/export it. It seems like it should be a fairly straightforward process (as shown at https://datatables.net/extensions/buttons/examples/html5/footer.html), but I can't get it to work properly.

Here is my script:

        $('#reportTable').DataTable(
        {

            dom: 'Blfript', // Blfrtip
            buttons:
            [
                {
                    extend: 'pdf',
                    footer: true,
                    className: 'green glyphicon glyphicon-file',
                    title: 'Report',
                    filename: 'Report',
                    exportOptions:
                    {
                        columns: [0, 1, 2, 3, 4, 5, 6, 7]
                    }
                },
                {
                    extend: 'excel',
                    footer: true,
                    className: 'green glyphicon glyphicon-list-alt',
                    title: 'Report',
                    filename: 'Report',
                    exportOptions:
                    {
                        columns: [0, 1, 2, 3, 4, 5, 6, 7]
                    }
                },
                {
                    extend: 'copy',
                    footer: true,
                    className: 'green glyphicon glyphicon-duplicate',
                    exportOptions:
                    {
                        columns: [0, 1, 2, 3, 4, 5, 6, 7]
                    }
                },
                {
                    extend: 'print',
                    footer: true,
                    className: 'green glyphicon glyphicon-print',
                    text: 'Print',
                    title: ' '
                }
            ],
            "footerCallback": function (row, start, end, display)
            {
                var api = this.api(),data;

                // Remove the formatting to get integer data for summation
                var intVal = function (i)
                {
                    return typeof i === 'string' ?
                        i.replace(/[\$,]/g, '') * 1 :
                        typeof i === 'number' ?
                            i : 0;
                };                  

                // Total over all pages
                total = api
                    .column(5)
                    .data()

                    .reduce(function (a, b)
                    {
                        return intVal(a) + intVal(b);
                    }, 0);

                // Total over all filtered pages
                if (api
                    .column(5,
                        {
                            search: 'applied'
                        })
                    .data()
                    .length)
                        {
                            pageTotal = api
                            .column(5, 
                                {
                                    search: 'applied'
                                })
                    .data()
                    .reduce(function (a, b) 
                        {
                            return intVal(a) + intVal(b);
                        });
                } else {
                    pageTotal = 0;
                }   
                
                // Total by category               
                var category = api.column(7).data().sort().unique().toArray();
                var totals = [];
                for (var i = 0; i < category.length; i++) totals.push(0);

                api.rows({ filter: 'applied' }).every(function ()
                {
                    var data = this.data();
                    totals[category.indexOf(data[7])] += intVal(data[5]);
                });

                // Remove any categories that have a "0" result
                html = [];            
                for (var j = 0; j < category.length; j++) {
                    if (totals[j] > 0) html.push(category[j] + ': ' + totals[j]);
                } 

                // Update footer
                $(api.column(5).footer()).html(html.length === 0 ? "" : html.join('</br>') + '</br>' + pageTotal.toFixed(2) + ' hours ( ' + total.toFixed(2) + ' total hours)'); 
            }
        });
    }
);

Here is my html:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>View/Edit Work Entries</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

<head>
    @* Links for the style sheets *@
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/jszip-2.5.0,dt-1.10.9,b-1.0.3,b-flash-1.0.3,b-html5-1.0.3/datatables.min.css" /> @* Needed for pagination and Copy button *@
    <link rel="stylesheet" type="text/css" href="~/Content/dataTables.bootstrap.css" /> @* Button and pagination styles *@
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> @* Style sheet used for DatePicker *@
    <link rel="stylesheet" href="/resources/demos/style.css"> @* Style sheet used for DatePicker *@

    @* Links for the DataTable and various buttons (PDF, Excel, Copy, Print) *@
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script> @* Required for DataTable *@
    <script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> @* Required for DataTable *@
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> @* Required for DataTable *@
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script> @* Required for all buttons *@
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script> @* Required for Copy, Excel, and PDF buttons *@
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script> @* Required for all buttons *@
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> @* Required for Excel button*@
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script> @* Required for PDF button *@
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script> @* Required for PDF button *@
</head>

@* Text boxes used for user input *@
<table border="0" cellspacing="5" cellpadding="5">
    <tbody>
        <tr>
            <td style="margin: 10px; padding: 5px;">Start Date:</td>
            <td><input name="min" id="min" type="text"></td>
        </tr>
        <tr>
            <td style="margin: 10px; padding: 5px;">End Date:</td>
            <td><input name="max" id="max" type="text"></td>
        </tr>
    </tbody>
</table>
@* Sets the header names *@
<table class="table" id="reportTable">
    <thead>
        <tr>
            <th width="100">
                Date
            </th>
            <th width="150">
                Name
            </th>
            <th width="150">
                Email
            </th>
            <th width="150">
                Description
            </th>
            <th width="150">
                Location
            </th>
            <th width="100">
                Work Hours
            </th>
            <th width="150">
                District
            </th>
            <th width="150">
                Subject Matter
            </th>
            <th></th>
        </tr>
    </thead>
    @* Gathers the data from SQL database *@
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.Work_Date)
                </td>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.User.User_Name)
                </td>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.User.User_Email)
                </td>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.Work_Description)
                </td>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.Work_Location)
                </td>
                <td align="center">
                    @Html.DisplayFor(modelItem => item.Work_Hours)
                </td>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.District.District_Name)
                </td>
                <td align="left">
                    @Html.DisplayFor(modelItem => item.New_Work.Category_Name)
                </td>
                @* Displays the Edit, Details, and Delete links *@
                <td width="225">
                    @Html.ActionLink("Edit", "Edit", new { id = item.Work_ID }) |
                    @Html.ActionLink("Details", "Details", new { id = item.Work_ID }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.Work_ID })
                </td>
            </tr>
        }
    </tbody>
    @* Displays the total within the footer *@
    <tfoot>
        <tr>
            <th colspan="7" style="text-align:right">Total: 0.0</th>
            <th></th>
        </tr>
    </tfoot>
</table>

@* Calls the script that handles the hour totals *@
<script type="text/javascript" src="~/Scripts/totalbuttons.js"></script>

@* Calls the script that handles the user inputs for the date range *@
<script type="text/javascript" src="~/Scripts/daterange.js"></script>
Viewing all 82203 articles
Browse latest View live


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