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

DataTables with currencyFormatter.js sort failure.

$
0
0

Hi @ all,

With following script I get a DataTables with a sum footer. I format all floats with currencyFormatter.js Combined with HTML-Tag class .monney. This works great. When I click a table headerlink to sort the table. All floats chance to -NaN €.
Has anybody a clou why this is happen and how to solve this.

$(document).ready(function() {

    $.get('stock.csv', function(data) {
        // start the table
        var html = '<table id="example" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">';

        // split into lines
        var rows = data.split("\n");

        // parse lines
        j = 0;
        rows.forEach(function getvalues(ourrow) {
                if (j == 0) {
                    // start a table row
                    html += "<thead><tr>";
                    htmltfoot = "<tfoot><tr>";

                    // split line into columns
                    var columns = ourrow.split(";");

                    var arrayLength = columns.length;
                    for (var i = 0; i < arrayLength; i++) {
                        html += "<th><div>" + columns[i] + "</div></th>";
                        if (i == 0){
                                htmltfoot += "<th class=\"sum\">Total:</th>";
                            } else {
                                htmltfoot += "<th class=\"sum money\">Total:</th>";
                            }
                    }
                    // close row
                    html += "</tr></thead>";
                    htmltfoot += "</tr></tfoot></tbody>";
                    html += htmltfoot;
                    j++;
                } else {
                    // start a table row
                    html += "<tr>";

                    // split line into columns
                    var columns = ourrow.split(";");

                    var arrayLength = columns.length;
                    for (var i = 0; i < arrayLength; i++) {
                        if (i == 0) {
                            html += "<th>" + columns[i] + "</th>";
                        } else {
                            if (columns[i] == 0){
                                html += "<td>" + columns[i] + "</td>";
                            } else {
                                html += "<td class='money'>" + columns[i] + "</td>";
                            }
                        }
                    }
                    // close row
                    html += "</tr>";
                }
            })
            // close table
        html += "</tbody></table>";

        // insert into div
        $('#container').append(html);
        $('#example').DataTable({
            "paging": false,
            "footerCallback": function(row, data, start, end, display) {
                var api = this.api();
                nb_cols = api.columns().nodes().length;
                var j = 1;
                while (j < nb_cols) {
                    var pageTotal = api.column(j, { page: 'current'}).data().reduce(function(a, b) {
                            if (b > 0) {
                            sumAB = Number(a) + Number(b);
                            return sumAB.toFixed(2)
                            }
                            else{return Number(a).toFixed(2);}
                        }, 0);
                    // Update footer
                    $(api.column(j).footer()).html(pageTotal);
                    j++;
                }
                OSREC.CurrencyFormatter.formatAll(
                {
                    selector: '.money',
                    currency: 'EUR'
                });
            }
        });
    });
    // Code here end
});

Upload image file name - incorrect

$
0
0

I need some help. I have been successful in uploading images and they are being stored on to my server. But the trouble is when I look in my database the file name is incorrect. Not sure why that it is.

According to my database the incorrect file name is "editor-fileName". But according to my saving feature of this line of code...

->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'] . '/images/.../profile__ID__.__EXTN__' )

This gives the correct file name on my server. But storing it into the database with this line of code is incorrect...

->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'] . '/images/.../profile__ID__.__EXTN__' )
                                ->db( 'Table', 'ID', array(
                                    'Field' => $pathToImg . Upload::DB_FILE_NAME
                                ) )

But according to the documentation: https://editor.datatables.net/manual/php/upload#Database-information

It says that "Upload::DB_FILE_NAME File name (with extension)"

But it's not doing what I want it to. How do I tell it the File Name is what I saved it to? How do I do that?

Editor Datatables - Requested unknown parameter 'Id' for row 142, column 0

$
0
0

I am using Editor Datatables to show records from my Oracle db in ASP.NET MVC. I have successfully implemented datatables. But the problem occurs when I try to inline edit a column and post back JSON from my controller to datatable.

HTML:

<div>
    <table class="display" cellspacing="0" id="trx_detail_tbl">
                                <thead>
                                    <tr>
                                        <th>Id</th>
                                        <th>Cutomer Id</th>
                                        <th>Customer Name</th>
                                        <th>Cheque Id</th>
                                        <th>Receipt Number</th>
                                        <th>Receipt Date</th>
                                        <th>Maturity Date</th>
                                        <th>Amount</th>
                                        <th>Currency</th>
                                        <th>Functional Amount</th>
                                        <th>Transaction Date</th>
                                        <th>Status</th>
                                        <th>Status Date</th>
                                        <th>Clearing Status</th>
                                        <th>Clearing Date</th>
                                        <th>Discounted Amount</th>
                                        <th>Comments</th>
                                        <th>Discounted</th>
                                    </tr>
                                </thead>
                            </table>
                        </div>

Javascript:

   ```

function getTransactionDetails(id) {
$("#trx-detail-div").show();

    editor = new $.fn.dataTable.Editor({
        ajax: {
            "url": "/ChequeDiscounting/SaveTransactionDetails",
            "type": "POST",
            "data": JSON.stringify(),
            "dataType": "json"
        },
        table: "#trx_detail_tbl",
        idSrc: 'ChequeId',
        fields: [{
            label: "Functional Amount:",
            name: "FunctionalAmount"
        }, {
            label: "Transaction Date:",
            name: "TransactionDate",
            type: "datetime"
        }, {
            label: "Status:",
            name: "Status",
            type: "select",
            options: [
                { label: 'Select Status', value: '0' },
                { label: 'Approved', value: '1' },
                { label: 'Rejected', value: '2' },
                { label: 'Bounced', value: '3' }
            ]
        }, {
            label: "Status Date:",
            name: "StatusDate",
            type: "datetime"
        }, {
            label: "Clearing Status:",
            name: "ClearingStatus",
            type: "select",
            options: [
                { label: 'Select Clearing Status', value: '0' },
                { label: 'Cleared', value: '1' },
                { label: 'Uncleared', value: '2' }
            ]
        }, {
            label: "Clearing Date:",
            name: "ClearingDate",
            type: "datetime"
        }, {
            label: "Discounted Amount:",
            name: "DiscountedAmount"
        }, {
            label: "Comments:",
            name: "Comments"
        }],
        formOptions: {
            inline: {
                onBlur: 'submit'
            }
        }
    });

    trxDetailTable = $('#trx_detail_tbl').removeAttr('width').DataTable({
        "stateSave": true,
        "scrollX": true,
        "filter": true,
        "ajax": {
            "url": "/ChequeDiscounting/GetTransactionDetails/" + id,
            "type": "POST",
            "dataType": "json"
        },
        "columns": [
            { "data": "Id" },
            { "data": "CustomerId" },
            { "data": "CustomerName" },
            { "data": "ChequeId" },
            { "data": "ReceiptNumber" },
            { "data": "ReceiptDate" },
            { "data": "MaturityDate" },
            { "data": "Amount" },
            { "data": "Currency" },
            { "data": "FunctionalAmount" },
            { "data": "TransactionDate" },
            { "data": "Status" },
            { "data": "StatusDate" },
            { "data": "ClearingStatus" },
            { "data": "ClearingDate" },
            { "data": "DiscountedAmount" },
            { "data": "Comments" },
            {
                "data": null,
                "render": function (data, type, row) {
                    if (row.IsDiscounted == 1)
                        return '<td>Already Discounted</td>';
                    else
                        return '<a onClick=checkDiscount(' + row.ChequeId + ');>Discounted</a>';
                }
            },
        ],
        "columnDefs": [
            //{
            //    "defaultContent": "-",
            //    "targets": "_all"
            //},
            { "width": 70, "targets": 0 },
            { "width": 300, "targets": 1 },
            { "width": 100, "targets": 2 },
            { "width": 100, "targets": 3 },
            { "width": 100, "targets": 4 },
            { "width": 100, "targets": 5 },
            { "width": 100, "targets": 6 },
            { "width": 110, "targets": 7 },
            { "width": 130, "targets": 8 },
            { "width": 110, "targets": 9 },
            { "width": 110, "targets": 10 },
            { "width": 100, "targets": 11 },
            { "width": 110, "targets": 12 },
            { "width": 100, "targets": 13 },
            { "width": 140, "targets": 14 },
            { "width": 200, "targets": 15 },
            { "width": 100, "targets": 16 },
        ],
        "fixedColumns": true,
        "order": [1, 'asc']
    });

    $('#trx_detail_tbl').on('click', 'tbody td:not(:first-child)', function (e) {
        editor.inline(this);
    });
    });
}

Controller:

[HttpPost]
public ActionResult SaveTransactionDetails(FormCollection form)
{
bool flag = false;

        int chequeId = Convert.ToInt32(form.Keys[1].Split('[')[1].Split(']').First());
        string columnName = form.Keys[1].Split('[')[2].Split(']').First();

        int functionalAmount;
        string transactionDate;
        string status;
        string statusDate;
        string clearingStatus;
        string clearingDate;
        int discountedAmount;
        string comments;
        string query;
        string serializedData = "";

        List<CustomerTransactionModel> tempList = new List<CustomerTransactionModel>();

        var customerTrxDetail = Shared.CustomerTransactionDetailsList.Where(a => (a.ChequeId == chequeId) && a.Id > 0).FirstOrDefault();
        var newCustomerTrxDetail = Shared.CustomerTransactionDetailsList.Where(a => a.ChequeId == chequeId).FirstOrDefault();

        if (columnName == "FunctionalAmount")
        {
            functionalAmount = Convert.ToInt32(form[1]);

            if (customerTrxDetail != null)
            {
                customerTrxDetail.FunctionalAmount = functionalAmount;
                tempList.Add(customerTrxDetail);
                serializedData = JsonConvert.SerializeObject(tempList);
            }
          }

        return Json(new { data = serializedData });
    }

Model:

public class CustomerTransactionModel
{
public int Id { get; set; }

public string ReceiptNumber { get; set; }

public string ReceiptDate { get; set; }

public int Amount { get; set; }

public string Currency { get; set; }

public int ChequeId { get; set; }

public string CustomerName { get; set; }

public int CustomerId { get; set; }

public string MaturityDate { get; set; }

public int FunctionalAmount { get; set; }

public string TransactionDate { get; set; }

public string Status { get; set; }

public string StatusDate { get; set; }

public string ClearingStatus { get; set; }

public string ClearingDate { get; set; }

public int DiscountedAmount { get; set; }

public string Comments { get; set; }

public int IsDiscounted { get; set; }

}
```

Issue is whenever I try to inline edit a column It gives me following error: DataTables warning: table id=trx_detail_tbl - Requested unknown parameter 'Id' for row 142, column 0. For more information about this error, please see http://datatables.net/tn/4

Stuck in this error for almost a day. Can someone please help me?``

buttons problem

$
0
0

first of all data table is a great plugin.
I have a problem when using buttons extensions only when refreshing the page.
I get an error dataTables.buttons.min.js:17 Uncaught Unknown button type: print.
I use this JS files: "~/Scripts/local/dataTables.buttons.min.js",
"~/Scripts/local/buttons.html5.min.js",
"~/Scripts/local/dataTables.colReorder.min.js",
"~/Scripts/local/buttons.semanticui.min.js",
"~/Scripts/local/buttons.colVis.min.js",
"~/Scripts/local/buttons.foundation.min.js",
"~/Scripts/local/buttons.print.min.js"
and my table code is :
table.DataTable({
dom: 'lfBrtip',
buttons: { buttons: ['copy', 'excel', 'pdf'] },
buttons: true, .....
can anyone help me sort the prooblem ??

Move editor popup window on the screen

$
0
0

Is there any way to make to popup editor window movable for the user? Currently I am using the Lightbox option and the position of the popup is static and does not allow to drag the window on the screen to see what is behind while editing.

Thanks, Denis

Field type "Title" error

$
0
0

Is it possible to use this filed type without 'name' attribute?
In the docs described that this type is not submitted to the server but I see that empty data sent from this filed and got an error after form submit.

Only displaying first datable clicked

$
0
0

debug

I have mutliple datatables on a site. Each menu link points to a different table. The first time I click a given link, the datatable loads, everything works fine. If I click on another link, the page loads (I can tell that the h1 tags have changed), but the datatable does not display.

The debugger shows the first 2 tables (which are no longer displayed), but not the third (Which should be displayed). I am completely confused!

Bootstrap 4 Alpha 6 Support

$
0
0

It seems that Bootstrap 4 Alpha 6 is not yet supported. The latest on the styling section https://datatables.net/examples/styling/bootstrap4.html seems to be for Alpha 5.

Is there a timetable for Alpha 6 support?

Seems like some of the changes may be small. I see in the dataTables.bootstrap4.js it references col-xs-*. The -xs no longer exists and should reference the -sm.


Problem with updating child row

$
0
0

Hello, I have a small problem with my datatable.
I have a table containing many rows and every row has a child a row that contains a form. When I submit this form using ajax, I receive a data that I use for updating the row. When the row is updated, only the value of the parent row is updated, to make the update on the child row visible, I need to hide the child row and show it again (no need to reload the page).
How can I do, to make the changes visibles automatically, without intervention of a human.
Here is my code : http://live.datatables.net/juvubuso/2/edit
You can seen the real issue at the end of the page, I made a comment about it.

Change background color child rows (responsive plugin)

$
0
0

Hello,

Some of my records have a color to indicate a status which is set in the rowcallback.
started using the responsive plugins, instead of hiding cols with bootstrap hidden-sm/xs. Anyway I wanted to have my child rows use the same color as the parent row. I have been trying this for quite a while, but have not succeeded so far. Does anyone have an idea on how to do this ?

Coloring the table is easy, since you can use the rendered. But I want to color the enire child row

I also use the option $.fn.dataTable.Responsive.display.childRowImmediate

Can't get datatables to work with json string

$
0
0

For some reason, despite following the tutorials to the letter (at least I think I am), I can't get the following to work. It gives me the dreaded:

**DataTables warning: table id=actiontables - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4**

Here is my code, someone please tell me what I am doing wrong..

<script>
jQuery(document).ready(function(){

var myjsons =[{"one":"195","two":"thing","three":"something","four":"1481200571","five":"test string","six":"www.google.com"}];

jQuery('#actiontables').DataTable( {
        data: myjsons,
        columns: [
            { myjsons: 'one' },
            { myjsons: 'two' },
            { myjsons: 'three' },
            { myjsons: 'four' },
            { myjsons: 'five' },
            { myjsons: 'six' }
        ]
    } );

}); </script>
<table id="actiontables" class="display" width="100%"></table>

using indexes

$
0
0

It's not clear to me from the documentation how indexes work.

give a table T
CurItem = Table.rows({ selected: true}); //single selection
Then I understand that
CurItemIndex = CurItem[0];

1) Can I assume that the previous item is at CurItemIndex - 1 if CurItemIndex > 0
2) Can I assume that the next item is at CurItemIndex + 1 if CurItemIndex < logTable.rows().indexes().length ?
(as long as all the items are visible)

Or do I need to do this

var TableIndexs = Table.rows().indexes();
if ( CurItem < TableIndexs.length - 1) {
nextItemIndex = TableIndexs(CurItem+1)
}
if (CurItem > 0) {
previtemIndex = TablesIndexes(CurItem-1)
}

Is the last item always given by
TableIndexs(TableIndexs.length - 1)

Thanks

Unable to display buttons

$
0
0

Attempting to use the Buttons extension, and not able to display the buttons, as per the documentation.
I've tried each of the methods, yet they are not showing.
Can you review my js on http://live.datatables.net/sojeluju/1/
Help show me what I'm missing.

$(document).ready( function () {
var table = $('#example').DataTable({
"sPaginationType" : "full_numbers",
"ajax": "/examples/server_side/scripts/server_processing.php",
"processing" : true,
"serverSide" : true,
"fixedHeader" : true,
"lengthMenu" : [[10, 25, 50, 100, 200, -1],[10,25,50,100, 200, "All"]],
"pageLength" : 25,
"sScrollX" : "110%",
"sScrollY" : "600px",
"bScrollCollapse": true,
"columnDefs": [
{ "type": "signed-num", "targets": 3}
],
dom: 'Bfrtip',
buttons: ['copy','excel','print']
});

        $('#example tfoot th').each(function() {
           var title = $('#example thead th').eq($(this).index()).text();
           console.log(title);
           $(this).html('<input type="text" placeholder="Search ' + title + '"/>');
       });
       table.columns().every(function () {
           var datatableColumn = this;
           $(this.footer()).find('input').on('keyup change', function() {
               datatableColumn.search(this.value).draw();
           });
       });

} );

Thank you,
Allan

Question about ID and VAR for multiple tables with Yadcf

$
0
0

I have a page with several datatables tables
I'm using the same var for each, only the ID is different.

var table = $('#list1').DataTable();
var table = $('#list2').DataTable();

First is it good to do that or I should use different var for each table?
If there are no problem to use the same var, how can I init Yadcf the the ID instead of the var?

Now I'm using
yadcf.init(table, [],);
and I'd like to init using ID instead of the var

could you provide the good syntax if possible

Thanks

Add 2nd line to row - similar to .child()

$
0
0

Hello,

is it possible to add a 2nd line with information to a row?

Thx for reply!


custom Button

$
0
0

One feature in my Project should be, that the User select a row and send the data, over a defined modal windows (in there to set the e-Mail Address,.. ) to one or more Athlete. The Modal windows are already loaded in the html. Is it possible to click on a Button, that open the modal windows and insert the selected row?
I read the extension select and Buttons. I have no idea, how can I do this. The select events example shows a example to get the Data, but how can I open the modal windows and put the Data in the Windows. In the Button Section I did not find any Information about that

Andreas

rowReorder does not update number in order column

$
0
0

I'm implementing datatables row reorder, and I'm able to reorder the rows just fine. The problem is that the 'order' column does not update to reflect the new row order for each row after the reorder. Below is my implementation. Everything is inside document.ready. Loaddata is called on document ready as well.

var routingtb;
        routingtb = $('#routingSegments').DataTable({
            "info": true,
            stateSave: true,
            "renderer": "bootstrap",
            "paging": false,
            "searching": false,
            "dom": '<Bfrtp>',
            select: true,
            rowReorder: true,
            buttons: [

            ]
        });


 routingtb.on( 'row-reorder', function ( e, diff, edit ) {
            var result = 'Reorder started on row: '+edit.triggerRow.data()[1]+'<br>';

            for ( var i=0, ien=diff.length ; i<ien ; i++ ) {
                var rowData = routingtb.row( diff[i].node ).data();

                result += rowData[1]+' updated to be in position '+
                    diff[i].newData+' (was '+diff[i].oldData+')<br>';
            }

            console.log( 'Event result:<br>'+result );
        } );

  function Loaddata() {
            routingtb.rows().remove().draw();
            $.ajax({
                url: "@Url.Action("someaction", "somecontroller")",
                type: "POST",
                dataType: "json",
                data: { someparameter: @Model.someproperty},
                success: function (data) {
                    $.each(data, function (i, item) {
                        routingtb.row.add([
                                item.RoutingOrder,
                          ... more columns here
                             "<button type='button' class='btn btn-primary btn-sm removeRouting'><span class='glyphicon glyphicon-remove'></span></button>",
                            ""
                        ]).draw(false);
                    });

                }
            });
        }

Scroll is not allowing overwrite of footer elements

$
0
0

Without the scrollX & scrollY parameters, the footer elements are successfully replaced with input boxes, allowing me to perform a column by column search. Once these parameters are included, the footer loses the input boxes.

I'm have this currently on http://live.datatables.net/sojeluju/1/edit

$(document).ready( function () {
var table = $('#example').DataTable({
"sPaginationType" : "full_numbers",
"ajax": "/examples/server_side/scripts/server_processing.php",
"processing" : true,
"serverSide" : true,
"fixedHeader" : true,
"lengthMenu" : [[10, 25, 50, 100, 200, -1],[10,25,50,100, 200, "All"]],
"pageLength" : 25,
"sScrollX" : "110%",
"sScrollY" : "600px",
"bScrollCollapse": true,
"columnDefs": [
{ "type": "signed-num", "targets": 3}
]
});

        $('#example tfoot th').each(function() {
           var title = $('#example thead th').eq($(this).index()).text();
           console.log(title);
           $(this).html('<input type="text" placeholder="Search ' + title + '"/>');
       });
       table.columns().every(function () {
           var datatableColumn = this;
           $(this.footer()).find('input').on('keyup change', function() {
               datatableColumn.search(this.value).draw();
           });
       });

} );

How do I create a search that looks for multiple things?

$
0
0

I have a map and when you click a state on it, my DataTable searches Column 7 for that state and displays all rows with it. So this works on click:

table.columns(7).search('"'+clickedState+'"', true, false).draw();

However, I now need it to also search in Column 8 for rows that match "Red" and I can't figure out how to modify that to include both. I've tried several different things and nothing is working. I'm sure it's something small i'm missing.

Psuedo code would be: if column 7 contains "clickedState" OR column 8 contains "Red", draw those rows.

Here is the demo I just set up: http://live.datatables.net/mejaxohi/1/edit

Resize column select as column width

$
0
0

I'm trying to implement a filter for specific columns. The every() of said columns is being delegated to the function below, but width is always turning out to be undefined. What am I doing wrong? Can somenone suggest another way to resize the select as the same width as the column?:

function filtroColuna () {
            var column = this;
            var width = column.width;
            console.log(width);
            var select = $('<select style="max-width:'+width+'px"><option value="">'+this.header().innerHTML+'</option></select>')
            .appendTo( $(column.header()).empty() )
            .on( 'change', function () {
                var val = $.fn.dataTable.util.escapeRegex(
                    $(this).val()
                );

                column
                    .search( val ? '^'+val+'$' : '', true, false )
                    .draw();
            });
            column.data().unique().sort().each( function ( d, j ) {
                select.append('<option value="' + d + '">' + d + '</option>')});
        }
Viewing all 81389 articles
Browse latest View live