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

Data Table code not working with client data loaded from a server. Please Help.

$
0
0

I tried to use dataTable code in my page. Table data is loaded from a server when I input a range of dates and click 'Get Details'. And I think because of this the search function is not working.All search fileds are present but none of them working the message 'No data available in the table.' How do i fix it.? See the code below.

<style type="text/css">
    tfoot input {
        width: 100%;
        padding: 3px;
        box-sizing: border-box;
    }
</style>

    <table id="example" class="display" cellspacing="0"  width="100%" border="1">
    <thead>
        <tr>
            <th>Sl.No</th>
            <th>Order Id</th>
            <th>Product</th>
            <th>City</th>
            <th>Mobile</th>
            <th>Order Date</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Sl.No</th>
            <th>Order Id</th>
            <th>Product</th>
            <th>City</th>
            <th>Mobile</th>
            <th>Order Date</th>
        </tr>
    </tfoot>
    <tbody>
         <tr ng-repeat="order in allOrders">
         <td>{{$index + 1}}</td>
         <td>{{order._source.orderid}}</td>
                <td>{{order._source.product}}</td>
                <td>{{order._source.city}}</td>
                <td>{{order._source.mobile}}</td>
               <td>{{order._source.order_date}}</td>
         </tr>
    </tbody>
</table></br></br>
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="dataTables.min.js"></script>
<script type="text/javascript">

    $(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

    // DataTable
    var table = $('#example').DataTable();

    // Apply the search
    table.columns().every( function () {
        var that = this;

        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );
} );


</script>

Edit single item and bubble editing not working for multiEditable set to false

$
0
0

In my datatable I have enabled both bubble editing and editing a single or multiple items after selection with main editing form.

If I disable multiEditable in a field, the field works only when clicking new button.
When I select a single item and click edit the field for which multiEditable has been disabled says that the input can only be edited individually. Is taht normal? Can i specify tomehow to the editing form that only a sinlge element is selected and why do i need to do that since the datatable knows how many elements have been selected anyway?
Even if I try to use bubble editing it says the same, even though bubble editing is by default for changing a single cell. Why?

For now I have left multiEditable enabled to avoid these issus but I would appreciate it if you could point me to the right direction.

I'm trying to copy forum discussion function multiply but result is [object Object]

$
0
0

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<title>Expense</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.2.4/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.1/css/select.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="../../css/editor.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="../resources/syntax/shCore.css">
<link rel="stylesheet" type="text/css" href="../resources/demo.css">
<style type="text/css" class="init">

</style>
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.4.js">
</script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js">
</script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js">
</script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.2.1/js/dataTables.select.min.js">
</script>
<script type="text/javascript" language="javascript" src="../../js/dataTables.editor.min.js">
</script>
<script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js">
</script>
<script type="text/javascript" language="javascript" src="../resources/demo.js">
</script>
<script type="text/javascript" language="javascript" src="../resources/editor-demo.js">
</script>
<script type="text/javascript" language="javascript" class="init">

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

$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "./php/expense.php",
table: "#expensetable",
fields: [ {
label: "Account:",
name: "expense.account",
type: "select"
}, {
label: "Currency:",
name: "expense.conversion"
}, {
label: "Quantity:",
name: "expense.quantity"
}, {
label: "Cost:",
name: "expense.cost"
}, {
"label": "Total:",
"name": "total",
type: "readonly",
}, {
label: "Comment:",
name: "expense.comment"
}
]
} );

function multiply () {
editor.field( 'total' ).val(
editor.field( 'expense.quantity' ).val() * editor.field( 'expense.cost' ).val()
);
}

editor.field( 'expense.quantity' ).input().on( 'keyup', multiply );
editor.field( 'expense.cost' ).input().on( 'keyup', multiply );

// Activate an inline edit on click of a table cell
$('#expensetable').on( 'click', 'tbody td:not(:first-child)', function (e) {
    editor.inline( this, {
        onBlur: 'submit'
    } );
} );

$('#expensetable').DataTable( {
    dom: "Bfrtip",
    ajax: {
        url: "./php/expense.php",
        type: 'POST'
    },
    columns: [
        {
            data: null,
            defaultContent: '',
            className: 'select-checkbox',
            orderable: false
        },
        { data: "expense.id" },
        { data: "expense.budget_id" },
        { data: "expense.job" },
        { data: "accounts.account_name", editField: "expense.account" },
        { data: "expense.conversion" },
        { data: "expense.quantity" },
        { data: "expense.cost" },
        { data: null, type:"readonly"},
        { data: "expense.comment" }

    ],
    order: [ 1, 'asc' ],
    select: {
        style:    'os',
        selector: 'td:first-child'
    },
    buttons: [
        { extend: "create", editor: editor },
        { extend: "edit",   editor: editor },
        { extend: "remove", editor: editor }
    ]
} );

} );

</script>

</head>
<body class="dt-example">
<div class="container">
<section>
<h1>Expense</h1>
<div class="info">
</div>
<div class="demo-html"></div>
<table id="expensetable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Row</th>
<th>Budget ID</th>
<th>Job</th>
<th>Account</th>
<th>Conversion</th>
<th>Quantity</th>
<th>Cost</th>
<th>Total</th>
<th>Comment</th>

                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th></th>
                    <th>Row</th>
                    <th>Budget ID</th>
                    <th>Job</th>
                    <th>Account</th>
                    <th>Conversion</th>
                    <th>Quantity</th>
                    <th>Cost</th>
                    <th>Total</th>
                    <th>Comment</th>

                </tr>
            </tfoot>
        </table>


        </div>
    </section>
</div>

</body>
</html>

Getting wrong message "Showing 151 to 144 of 144 records"

$
0
0

When i change the show count value, while on the last page, results in a blank page being added to the page display. & If the last page is selected "No records were found" is displayed and showing count is outside of the range of available records.
"Showing 151 to 144 of 144 records"

Pagination buttons cause blur when blurable is enabled

$
0
0

When Select is enabled and select.blurable is active, the selection is blurred when changing the current page by clicking the pager buttons.

http://live.datatables.net/xayarene/1/edit?js,output

This happens because the page buttons are removed from the DOM before Select has a chance to determine if the click was inside the table container.

I fixed it by changing Select to ignore clicks on elements that are not currently in the DOM.

    if ( ctx._select.blurable ) {
      // If the click was on a node that has since been removed from the DOM, don't blur
      if (e.target.getRootNode() !== document) {
        return;
      }
     ...

How to render read only Editor field

$
0
0

Hi all,

i am currently implementing read only fields on my DataTable with inline edit enabled. My problem is that i cant find a way to render the values for inline edit. Columns have an attribute called render where you can call a function to render the value. I am currently missing the same for the editor inline edit fields. Is there a way to work around this? I cant live with unrendered values when clicking a read only inline edit field.

I tried to use the def attribute with a function call for the existing render functions, but that does not work.

Add row and delete row

$
0
0

Hi,
With an a ajax I add a row:

            $.ajax({
              url: '<?php echo base_url();?>roles/saveRoles',
              data:datos,
              type: "POST",
              success: function(msg) {
                var row = table.row($(this).parents('tr')).data();
                console.log(msg);
                var dat = $.parseJSON(msg);
                  if(dat.msg == '1')
                    generate('success','El registro fue guardado satifactoriamente.');
                  else
                    generate('error','Ocurrió un error al guardar el registro.');
                  $('#rol').val('');
                  $('#descripcion').val('');
                  $("#foo").modal('hide');
                        table.row.add( [
                            dat.data.id,
                            dat.data.rol,
                            dat.data.descripcion,
                            dat.data.status,
                            dat.data.accion
                        ] ).draw( false );
                }
            });

And I need to send the id by post:

        $('#datatable tbody').on( 'click','#delreg',function() {
          // var dat = table.row($(this).parents('tr')).data();
          var row = table.row($(this).parents('tr')).data();
          console.log(row[0]);
          $.ajax({
            url: '<?php echo base_url(); ?>roles/delRol',
            data: {id:row[0]},
            type: 'POST',
            success: function(msg){
              // table.row($(this).parents('tr')).remove().draw();
              // var row = table.row($(this).parents('tr'));
              // row.remove().draw();
            }
          });
        });

When the record is added with table.row.add().draw() does not send the post, but if it is loaded by default, it does

Use child row to display all self referencing table rows

$
0
0

Hello, I have a DB table structured the following way:

https://gyazo.com/c8d2c95703a12f788767b00ccb8a9524 (Child PK)

Basically, I want the child columns with parent null and their descriptions to be displayed first. Then I want the child columns that are referenced to their parent to be displayed under.

So if you use this picture as a reference it would look like: https://gyazo.com/102731409cd5847ec2ca9320fc0b6228

DimCustomer - Customer Dimension
Name - Customer's name
Country - Customer's country

Is it possible to somehow loop through this? Ideas, tips, example codes, everything will be appreciated. Thanks :)

<html>
        <div style="max-width:70%; margin:0 auto">
        <table id="myDatatable" class="display responsive" width="100%">
            <thead>
                <tr>
                    <th class="all">Table</th>
                    <th class="all">Description</th>
                    <th class="none"></th>
                </tr>
            </thead>
        </div>

</html>


<script>
            $(document).ready(function () {
                var oTable = $('#myDatatable').DataTable({

                    "ajax": {
                        "url": '/home/GetTable',
                        "type": "get",
                        "datatype": "json"
                    },

                    "columns": [

                        {"data": "Child", "autoWidth": true},
                        { "data": "Description", "autoWidth": true },
                        { "data": "Parent", "autoWidth": true },



                    ],


                })


            })

        </script>


```
public ActionResult GetTable()
{
using (DBEntities dc = new DBEntities())
{
var table = dc.Tables.Where(a => a.Parent == null).ToList();
return Json(new { data = table }, JsonRequestBehavior.AllowGet);
}
}

```


Custom Filter not working

$
0
0

Hi,

Im having a problems filter rows based on a condition.

These are my two rows of interest:
<td class="seven-day-filter">@_event.SevenDayFilter</td>
<td class="thirty-day-filter">@_event.ThirtyDayFilter</td>

They are in a paged DataTable.

Here is my Javascript for the Seven Day Filter:

$("#show-seven-day-rows").click(function () {
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
return $(oTable.row(dataIndex).cell('.seven-day-filter').data()==7);
}
);
oTable.draw();
});

No errors in the console...it just plain doesn't do anything.

What am I doing wrong?

Thanks,
Ron

Fixed columns problem

$
0
0

Hi,
I have 2 datatables on same page. Until now both datatables looks fine with them styles. Today I download jquery.dataTables.min.js and dataTables.fixedColumns.js and *.css too in order to use fixed columns.
First datatable still looking good but the second loosing styles. The columns loose width, alignment, all styles.
All pages with 2 or more datatables have same problem.

FixedColumns and Scroller in IE11

$
0
0

I use FixedColumns together with Scroller. I get inconsistent scrolling in IE11 doing this:
1. scroll down with the scrollbar on the right so scroller loads new rows
2. use the mouse wheel over fixed columns
Result: Only the fixed columns scroll with the mouse wheel, not the other columns.

It works correctly in Firefox and Chrome. And it works correctly in IE11 if I only use the mouse wheel and not the scrollbar on the right.

Modificar la cantidad de filas de la tabla por medio de un valor filtrado

$
0
0

Estoy haciendo una herramienta de citas que dependiendo del tipo de servicio de la cita que se este seleccionando el deberá cambiar la cantidad de filas que se muestran en la tabla?

How do I render a cells value based on a value from the previous row

$
0
0

Hello again,

I'm trying to render a cell value or even style based on the previous rows value for the same cell. Ive played around with it a bunch and can't seem to get it.

Basically if the first columns value is the same as the previous row, I want it to to be blank, otherwise give me the value.

Here is what I am getting as a result....followed by what I want
AS is

EIN / SSNDoctorNPIGroup / Individual
123456SMITH, BOBIndividual
654321Group
654321JONES, MIKEIndividual
654321JACKSON , JOHNIndividual

What Im trying to do:

EIN / SSNDoctorNPIGroup / Individual
123456SMITH, BOBIndividual
654321Group
JONES, MIKEIndividual
JACKSON , JOHNIndividual

Here is my current code

    function LoadNpiDataTable(route : string) {
        $('#NpiTable').DataTable({
            "ajax": route,
            "destroy": true,
            "columns": [
                { "title": "EIN / SSN", data: function (data) { return "<a class='editNpiLink' data-id=" + data.TaxId + " data-docId=" + data.DocId + " >" + data.TaxId + "</a>" } },
                { "title": "Doctor", "data": "Name" },
                { "title": "NPI", "data": "Npi" },
                {
                    "title": "Group / Individual", data: function (data) {
                        if (data.Type == 1) {
                            return "Individual"
                        }
                        else return "Group"
                    }
                }
            ]
        });
    }

Thanks in advance, any help is greatly appreciated

get data from input element in table after change page

$
0
0

Hi,
I tri to use my function to export all input elements in datatables (same function of datatables with few changes), but but the problème is that whene i change an element and change page, if clic export the vale of element changed is not correcte. i have the initial data.
Can you help me ?
sorry about my English :)

code :

$.fn.dataTable.Api.register( 'buttons.exportData()', function ( options ) {
if ( this.context.length ) {
var dt = new $.fn.dataTable.Api(this.context[0]);

            var _exportTextarea = $('<textarea/>')[0];
            var config = $.extend( true, {}, {
                rows:           null,
                columns:        '',
                modifier:       {
                    search: 'applied',
                    order:  'applied'
                },
                orthogonal:     'display',
                stripHtml:      true,
                stripNewlines:  true,
                decodeEntities: true,
                trim:           true,
                format:         {
                    header: function ( d ) {
                        return strip( d );
                    },
                    footer: function ( d ) {
                        return strip( d );
                    },
                    body: function ( d ) {
                        return strip( d );
                    }
                }
            }, options );

            var strip = function ( str ) {
                if ( typeof str !== 'string' ) {
                    return str;
                }

                if ( config.stripHtml ) {
                    str = str.replace( /<[^>]*>/g, '' );
                }

                if ( config.trim ) {
                    str = str.replace( /^\s+|\s+$/g, '' );
                }

                if ( config.stripNewlines ) {
                    str = str.replace( /\n/g, ' ' );
                }

                if ( config.decodeEntities ) {
                    _exportTextarea.innerHTML = str;
                    str = _exportTextarea.value;
                }
                if ($.isNumeric(str.replace( / /g, '' ))) {
                    //str = str.replace( / /g, '' );
                    str = str.replace(".", ',' );
                }
                return str;
            };


            var header = dt.columns( config.columns ).indexes().map( function (idx) {
                var el = dt.column( idx ).header();
                return config.format.header( el.innerHTML, idx, el );
            } ).toArray();

            var footer = dt.table().footer() ?
                dt.columns( config.columns ).indexes().map( function (idx) {
                    var el = dt.column( idx ).footer();
                    return config.format.footer( el ? el.innerHTML : '', idx, el );
                } ).toArray() :
                null;

            var rowIndexes = dt.rows( config.rows, config.modifier ).indexes().toArray();
            var selectedCells = dt.cells( rowIndexes, config.columns );
            var cells = selectedCells
                .render( config.orthogonal )
                .toArray();
            var cellNodes = selectedCells
                .nodes()
                .toArray();

            var columns = header.length;
            var rows = columns > 0 ? cells.length / columns : 0;
            var body = new Array( rows );
            var cellCounter = 0;

            for ( var i=0, ien=rows ; i<ien ; i++ ) {
                var row = new Array( columns );
                for ( var j=0 ; j<columns ; j++ ) {
                    var val = cellNodes[cellCounter] ? cellNodes[cellCounter].innerHTML : cells[cellCounter];
                    val = "<div>" + val + "</div>";
                                            // priority is for select if not existe, get data from textbox if existe, if not get data from cell
                    var selectChield = $(val).children('select')[0];
                    if (selectChield) {
                        val = $(selectChield).find('option:selected').text();

                    } else {
                        selectChield = $(val).find('input').filter(':visible').not(':input[readonly]')[0];
                        if (selectChield) {
                            val =  $(selectChield).val();
                        }
                    }
                    row[j] = config.format.body( val, i, j, cellNodes[ cellCounter ] );

                    cellCounter++;
                }

                body[i] = row;
            }

            return {
                header: header,
                footer: footer,
                body:   body
            };
        }
    } );

How can I set a color in a row

$
0
0

How can I set a color in a row based on the value from database. Thanks


statesave type option for child row state

$
0
0

i have been modifying a datatable to add a child row - as the number of fields displayed was making the row a bit cluttered - much better now !

Most elements of the child row are links to related pages, each with a back button to my main page.

what i would like to do is retain the child row in its open state when going back to the page.

is there a built in way to do this ?

Changing the params on an AJAX sourced table

$
0
0

I have a table that uses the ajax feature to retrieve the data. Above the table, there's a search form, and when someone submits a search, I wanted to have the DataTable re-query the AJAX source, but with different parameters.

I see there's an ajax.params() feature, but that looks like its only for retrieving the parameters, not setting new ones.

It looks like I can do something like:

table.ajax.url( 'ajax-data.php?company_id=1291' ).load();

But I hate having to do that, its just... UGLY!

Thanks!

parse data table from ajax URL

$
0
0

Hi,
I'm trying to parse a REST service response as a Data table but I need to show only some columns in the table and to change columns name.

Is any way to accomplish this goal with datatables API?

Thanks in advance,
Laura

dateformat

$
0
0

Hi,

in my example I tried to set a dateformat in this way:
{
label: "SellDate:",
name: "sellDate",
def: function () { var d = new Date(); return new Date(d.getFullYear(), 11, 31); },
type: "datetime",
dateFormat: "dd.mm.YYYY"
},

or
{
label: "Date:",
name: "_stocks_fees.date",
type: "datetime",
dateFormat: "dd.mm.YYYY"
}
but it seems that the dateFormat variables were ignored and the date in the form and in the tables is still YYYY-MM-DD.

What did I wrong?

Thanks for any support

Patrick

Replace commas with dots

$
0
0

Hi,

I have some fields where I use "float" numbers (e.g. 2.81) and when I copy values from a source the numbers will be provided with a comma (like 2,81).

Is there a solution to replace the comma while/after paste it into the field?

Thanks in advance

Patrick

Viewing all 81395 articles
Browse latest View live


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