Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all 1816 articles
Browse latest View live

FooterCallback - both totals coming back as page totals

$
0
0

I'm using the footerCallBack and the Page Total and Total amounts are the same. Here's my code:

    <script type="text/javascript" language="javascript" class="init">

        $.extend( $.fn.dataTable.defaults, {
            responsive: true
        } );        
        
        $(document).ready(function() {
            $('#example').dataTable( {
        "footerCallback": function ( row, data, 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( 4 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                } );
 
            // Total over this page
            pageTotal = api
                .column( 4, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            // Update footer
            $( api.column( 4 ).footer() ).html(
                pageTotal +' ('+ total +' total)'
            );
        },              
                "language": { "infoFiltered": ""},          
                "order": [[ 1, "desc" ]],
                "processing": true,
                "serverSide": true,
                "ajax": {
                        "url": 'scripts/server_processing_activity.php',
                "data": {                        
                    formCustomer: '<?php echo $_POST["sel_customer"] ?>',  
                    formStartDate: '<?php echo $_POST["dp3"] ?>',
                    formEndDate: '<?php echo $_POST["dp4"] ?>',
                    }               
                }
                            
            } );
        } );

    </script>   

Can Not obtain data from mySql

$
0
0

Hello folks, I am new to datatables and am having a heck of a time getting started. I can not even get the examples to work right. I am using Windows 7 Professional, WebMatrix 3, PHP v 5,4 and MySQL v5. I created a database "testexamples" and was able to load the example data just fine. So I gutted a page and tried to rework it to use my database. It goes nowhere. I am not using the Editor. And wish to use server-side etc. I am also rather confused about the ssp.class.php. I understand the coding but and I to execute this in MySQ?? I see it rederence and rather confused about it. My datatables folder is located on drive c. I have a problem with the examples working too. Just for kicks I deleted some records, execute an example and the records still appeared but they shouldn't cause I had deleted them, I just want to get going here and quickly too. Any help is appreciated.. Below is my coding:

 <?php 
    require_once ("myserver_processing.php"); 
include("ssp.class.php") 
 ?> 
 <html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">

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


<script type="text/javascript" language="javascript" class="init">


$.extend( true, $.fn.dataTable.defaults, {
    "searching": false,
    "ordering": false
} );


$(document).ready(function() {
    $('customermaster').DataTable();
} );
</script>



</head>
<body>
    <table>
                <thead>
                    <tr>
                        <th>firstname</th>
                        <th>middlename</th>
                        <th>lastname</th>
                        <th>email</th>
                    </tr>
                </thead>

                <tfoot>
                    <tr>
                        <th>First</th>
                        <th>Middle</th>
                        <th>Last</th>
                        <th>Email</th>
                    </tr>
                </tfoot>
            </table>

</body>
</html>

AJAX data source throwing TypeError: b[a] is undefined

$
0
0

(debug code ucolef )

I'm trying to get my tables working with an AJAX source (client-side processing). The table definition looks like this:

var bbTable = $('#bb_datatable').DataTable({

            "sDom": "<'row  bottom-buffer10' <'.col-sm-4'><'.col-sm-4'> <'.col-sm-4 pull-right' f>>t<'row'<'.col-sm-8'i r><'pull-right'>S>",
            "columns" : [
                {
                    'data': 'field_id_59',
                    'bVisible' : true
                },
                {
                    'data': 'field_id_60',
                    'bVisible' : true
                }
            ],
            "scrollY": "600px",
            "scrollCollapse": true,
            "paginate": false,
            "order" : [],
            "select": "single",
            "buttons": [],
            "ajax": {
                "url": bb.ajaxPath,
                "data": function ( d ) {
                    return $.extend( {}, d, {
                        "action": "fill-datatable",
                        "query_id": 28,
                        "col_prop_name_array": ['field_id_59', 'field_id_60']
                    } );
                }
            }
        }
    );

The AJAX call returns something that looks identical to the analogous examples on this site:

{
    "data": [{
        "field_id_59": "1",
        "field_id_60": "BigBench Adminx"
    }, {
        "field_id_59": "2",
        "field_id_60": "BigBench Mouse "
    }]
}

...and datatables then throws the above error.

If, instead of "ajax: ", I specify the following, no error is generated:

"data": [{"field_id_59":"1","field_id_60":"Big Bench Adminx"},{"field_id_59":"2","field_id_60":"Big Bench Mouse"}],

Comparison of this problem to some previous posts in this forum suggests that Datatables doesn't like the JSON that is being returned. I know that I used to specify iTotalRecords and iTotalDisplayRecords in the JSON object that was returned but this seems to have been deprecated in 1.9x for client side processing?

Thanks in advance,

Rob

ajax.reload keep inline edit

$
0
0
        table.ajax.reload(null, false);
            console.log('ajax.reload');
    }, 10*1000 );

My table every 10 seconds reload.
If I'm editing while reload,Edit box disappears.

Please see GIF.

Thank you for your help.

Column alignment with ScrollY

$
0
0

Hi,

I have a table which works perfect until I use scrollY, I've tried using columns.adjust()
with no luck. Any suggestions?

Thnx!

Downloader page not current?

Using postCreate and postEdit together

$
0
0

I am able to use both postCreate and postEdit individually successfully. When used together only the postEdit works. I am trying to create table entries of the user and the date when a records are created and when they are edited, when the Add button is used then postCreate is triggered and when the edit button is clicked the postEdit is triggered. The example given works fine because the postEdit only updates one field, in mine I need two fields updated. Please help

Example of using the mjoinMinCount validation

$
0
0

Hi!

I'm struggling to understand how to use the new Validate:mjoinMinCount() validation. Reading the manual this was my best guess of how to use it but this does not validate:

 ->join(
            Mjoin::inst( 'genres' )
                ->validator('genres[].id', Validate::mjoinMinCount(1))
                 ->link( 'contacts.id', 'contacts_genres.contact_id' )
                 ->link( 'genres.id', 'contacts_genres.genre_id' )
                 ->order( 'genres.genre asc' )
                 ->fields(
                     Field::inst( 'id' )
                          ->validator(Validate::required())
                          ->options( Options::inst()
                                            ->table( 'genres' )
                                            ->value( 'id' )
                                            ->label( 'genre' )
                      ),
                     Field::inst( 'genre' )
                 )
        )

Could you point me in the right direction?

Thanks!


Example for DataTables Editor w/ASP.NET Core/Razor Pages

$
0
0

I've read every article matching +datatables +asp.net +core, 13 times over and can't get anywhere with getting DataTables Editor working on ASP.NET Core w/Razor Pages. Most of the examples are utilizing either ApiController (which no longer exists in ASP.NET Core), or DataTables (without the Editor). We're attempting to get this working on Razor Pages so we can continue migrating our WebForms pages to Asp.Net Core / Razor Pages.

Full MVC seemed a bit overkill/messy for us (it's a relatively small app) so the new RazorPages Syntax and smaller application footprint seems to suite our needs well. This is what we've got handling the response to the DataTables Editor code (which is also copied from our MVC App with an update to the URL string:

[HttpGet]

public JsonResult OnGetReturnQuoteItems(int QuoteID)
{
    MySqlConnection myConnection = new MySqlConnection(Configuration.GetConnectionString("blah"));
    using (var db = new Database("mysql", myConnection))
    {
        var response = new Editor(db, "QuoteItems", "QuoteItemID")
             .Model<Models.blah.QuoteItems>()
             .Where("QuoteID", QuoteID, "=")
            .Process(Request.Form) // In WebForms this was .Process(Request) which .Net Core doesn't like.
            .Data();
        return new JsonResult(response); // In WebForms, this was return Json(response);
    }
}

Our URL String in HTML is set to:

/QuoteEdit?handler=ReturnQuoteItems&QuoteID=" + getUrlVars()["QuoteID"]

If there's a better way to do this, I'd love some direction as to what we're doing wrong. Ideally we'd like to use the EF DbContext vs calling a separate DBConnection but couldn't find any good examples with that and DataTables Editor either.

different sql result sets

$
0
0

When I run this server script (php) I get a result set having a size of 2,970 rows.

<?php

/*
 * Editor server script for DB table accounts
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'accounts', 'id' )
        ->fields(
                Field::inst( 'accounts.name' ),
                Field::inst( 'LENGTH( accounts.name) AS accounts.name_length' ),
                Field::inst( 'crm_sites.name' ),
                Field::inst( 'LENGTH( crm_sites.name) AS crm_sites.name_length' )
        )
        ->leftJoin( 'accounts_cstm', 'accounts.id', '=', 'accounts_cstm.id_c' )
        ->leftJoin( 'crm_sites_accounts_1_c', 'accounts.id', '=', 'crm_sites_accounts_1_c.crm_sites_accounts_1accounts_idb' )
        ->leftJoin( 'crm_sites', 'crm_sites.id', '=', 'crm_sites_accounts_1_c.crm_sites_accounts_1crm_sites_ida' )
        ->where( 'accounts.name', 'crm_sites.name', '!=', false )
        ->where( 'accounts.deleted', 0, '=' )
        ->where( 'crm_sites.deleted', 0, '=' )
        ->where( 'crm_sites_accounts_1_c.deleted', 0, '=' )
        ->debug( true )
        ->process( $_POST )
        ->json();

The sql query and bindings generated by the Editor are:

0   {…}
query   SELECT `accounts`.`id` as 'accounts.id', `accounts`.`name` as 'accounts.name', LENGTH( accounts.name) as 'LENGTH( accounts.name)', `crm_sites`.`name` as 'crm_sites.name', LENGTH( crm_sites.name) as 'LENGTH( crm_sites.name)' FROM `accounts` LEFT JOIN `accounts_cstm` ON `accounts`.`id` = `accounts_cstm`.`id_c` LEFT JOIN `crm_sites_accounts_1_c` ON `accounts`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1accounts_idb` LEFT JOIN `crm_sites` ON `crm_sites`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1crm_sites_ida` WHERE `accounts`.`name` != :where_0 AND `accounts`.`deleted` = :where_1 AND `crm_sites`.`deleted` = :where_2 AND `crm_sites_accounts_1_c`.`deleted` = :where_3
bindings    […]
0   
name    :where_0
value   crm_sites.name
type    null
1   {…}
name    :where_1
value   0
type    null
2   {…}
name    :where_2
value   0
type    null
3   {…}
name    :where_3
value   0
type    null

When I copy the query and replace the :where_[0-3] with the appropriate values I get the following query:

SELECT `accounts`.`id` as 'accounts.id', `accounts`.`name` as 'accounts.name', LENGTH( accounts.name) as 'LENGTH( accounts.name)', `crm_sites`.`name` as 'crm_sites.name', LENGTH( crm_sites.name) as 'LENGTH( crm_sites.name)' FROM `accounts` LEFT JOIN `accounts_cstm` ON `accounts`.`id` = `accounts_cstm`.`id_c` LEFT JOIN `crm_sites_accounts_1_c` ON `accounts`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1accounts_idb` LEFT JOIN `crm_sites` ON `crm_sites`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1crm_sites_ida` WHERE `accounts`.`name` != `crm_sites`.`name` AND `accounts`.`deleted` = 0 AND `crm_sites`.`deleted` = 0 AND `crm_sites_accounts_1_c`.`deleted` = 0 ;

When I run this I get a result set of 89 rows (what I was expecting).

What am I missing.

The query is joining two tables with a map table and is comparing the 'name' fields and should return only those that do not match.

Datatable stops functioning...

$
0
0

Happy Evening,

Suddenly all my data table suddenly stopped working in my website in all pages.

Looks wired, it happened couple of days back and solved by itself - again it happens today. Please help me solves this. I am in a middle of a project and it really needed for us to execute invoice process.

Wishing you Most and more...
Bala.

Fatal Error when validating input

$
0
0

I'm using editor 1.9.1 and when I try to add an entry to the database the "Validate::dbValues" throws the following error.

Fatal error:  Uncaught Error: Call to undefined function DataTables\Editor\mb_strlen() in /var/www/html/php/Editor/Validate.php:635
Stack trace:
#0 [internal function]: DataTables\Editor\Validate::DataTables\Editor\{closure}('T23456', Array, Object(DataTables\Editor\Field), Array)
#1 /var/www/html/php/Editor/Field.php(674): call_user_func(Object(Closure), 'T23456', Array, Object(DataTables\Editor\Field), Array)
#2 /var/www/html/php/Editor.php(814): DataTables\Editor\Field-&gt;validate(Array, Object(DataTables\Editor), '0')
#3 /var/www/html/php/Editor.php(996): DataTables\Editor-&gt;validate(Array, Array)
#4 /var/www/html/php/Editor.php(683): DataTables\Editor-&gt;_process(Array)
#5 /var/www/html/users-con.php(61): DataTables\Editor-&gt;process(Array)
#6 {main}
  thrown in /var/www/html/php/Editor/Validate.php on line 635

If I comment out "Validate::dbValues" editor works fine and adds the entry to the table. Any ideas?

Does editor support a select type when using a VIEW?

Mjoin

$
0
0

in Node.js ,run parent/child editor,console display unhandled promise error:[object Promise]ReferenceError:mjoin is not defined,why?

Popup Editor - Save but not dismiss.

$
0
0

Is there the possibility of adding a second button within the popup editor that would do a Save but not dismiss the editor like Update does?


Is there a render function to limit characters displayed in a field in table view?

$
0
0

I have a table with half a dozen fields to display in table view. One of these is a comments field which could be a few words to a Michener novel. In PHP I can do something like:

$text = substr ($text,0,80);
if ( strlen ($text > 80 ) ) { $text = "$text ..."; }

An example please how to do this in datatables?

Bt the way, just wondering which formatting editor you are using here in the forum.

Self-referencing left join

$
0
0

Hi

I'm trying to convert the following sql into valid server DT code but I'm struggling a bit translating the aliases and embedded select statement in the left join.

  • Here's the sql:

SELECT V.ID, ISNULL(V.CustomerIndex, C.CustomerIndex) as CustomerIndex

FROM GlobalPriceLists as V

LEFT JOIN (SELECT CustomerIndex, ListType, ListName FROM GlobalPriceLists WHERE CustomerIndex = 0) as C

ON C.ListType = V.ListType AND C.ListName = V.ListName AND V.CustomerIndex = 1

  • Server code so far:

editor = new Editor(db, "GlobalPriceLists", "GlobalPriceLists.id")
.Model<CustomerSNsDBModel.GlobalPriceLists>("GlobalPriceLists");
editor.Field(new Field("GlobalPriceLists.id")
.Set(false)
);
editor.MJoin(new MJoin("GlobalPriceLists")
.Model<PriceListsDBModel>()
.Name("GlobalPriceLists.CustomerIndex")
.Link("GlobalPriceLists.ListType", "GlobalPriceLists.ListType")
.Link("GlobalPriceLists.ListName", "GlobalPriceLists.ListName")
.Where(q =>
q.Where("GlobalPriceLists.CustomerIndex", lngCustIdx, "=")
)
.Order("GlobalPriceLists.id ASC")
.Field(new Field("id")
.Options(new Options()
.Table("GlobalPriceLists")
.Value("id")
.Label("CustomerIndex")
)
.Set(false)
)
.Set(false)
);
editor.Field(new Field("GlobalPriceLists.ListType")
.GetFormatter((val, data) => CommonUtilities.IsNullOrEmpty(val) == true ? 0 : val)
);
editor.Field(new Field("GlobalPriceLists.ListName")
.GetFormatter((val, data) => CommonUtilities.IsNullOrEmpty(val) == true ? string.Empty : val)
);
editor.LeftJoin("GlobalPriceLists AS C", "GlobalPriceLists.id", "=", "GlobalPriceLists.SubPackID");
editor.Where("GlobalPriceLists.CustomerIndex", 0);
editor.Debug(true);
editor.Process(formData);

Thanks a lot.

Reloading a DT with an array as its source

$
0
0

Hi

This page gives a number of examples of how to load/reload some ajax data but how is this achieved with a js object array? I'm setting a DT with an array and have a refresh button but can't see how to reload the Dt with the array again after the array has been modified via ajax. Thanks.

This works on 1st load of the page only and the page above states a function needs to be used if data needs reloading:

(...)
dom: 'Bfrtip',
data: arrPrLiParams,
columns: [...]

During importing the dataset why certain field is always asking about the "Undo changes"?

$
0
0

I've around 200 records dataset which already created by the datatable editor. After exporting the dataset and try to import it again from there it always come up with "Undo changes" for a particular field value.
I have more than 30 fields values and some are conditional ones(depend on the value of another field).
The field I am pointing out is also a conditional one and it's not the only conditional field.
Please let me know any clue to work out?
-Sanjaya

Npm datatables.net support

$
0
0

this npm("npm install --save datatables.net') is providing only js files. css files are not coming. I have downloade and added manually and it's working locally but when it's come to deployment in live server we are giving 'npm install' that time it's not finding since it's added manually. what is the solution for this?

let me know if any other details are required.

Viewing all 1816 articles
Browse latest View live