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

How to prevent XSS when using columns.render to render e.g. a link?

$
0
0

I have a table that loads its data via ajax, and I want hyperlinks in a column. I did something similar as in the fourth example in the columns.render documentation.

$('#mytable').DataTable({
  'ajax': { /* ... */ }
  'columns': [
    {
      'data': 'label',
      'render': function (data, type, row, meta) {
        return '<a href="' + /* url goes here */ + '"> + data + '</a>';
      }
    }

This works nicely, but it is vulnerable for XSS. If the ajax call returns some malicious html inside the json, there will be troubles. I read about the text helper to prevent such exploits. But is there a way to get data processed by the text helper, before it is used to create the link? I cluelessly tried the following:

$('#mytable').DataTable({
  'ajax': { /* ... */ }
  'columns': [
    {
      'data': 'label',
      'render': function (data, type, row, meta) {
        var sanitized = $.fn.dataTable.render.text(data, type, row, meta);
        return '<a href="' + /* url goes here */ + '"> + sanitized + '</a>';
      }
    }

but that did not work.


Generator not working anymore?

$
0
0

Hello Allan,

I think something is wrong with the generator. I get an error message similar to https://datatables.net/forums/discussion/37793
Code CD1674. "Database": type used in the statement must be implicitly convertible to 'System.IDisposable'

Thank you in advance and also for the editor component!
Best regards,
Markus

Removing search in filter keeps the number of filtered rows

$
0
0

Hi !

My datatables works with Ajax and when I make a search in the filter input and delete my search, it returns only the number of rows were filtered.

For example :

I have

element 1
element 2
element 3
Then, I searched "3", that returns :

element 3
But, if I remove my search : "3", it returns only :

element 1
Or I want to get back :

element 1
element 2
element 3
Do you have any idea ?

BTW, the pageResize doesn't work anymore..

Thanks for reading.

draw() not working after table refresh with AJAX

$
0
0

Hi,
I have a table where i used footer callback like in the example https://datatables.net/examples/advanced_init/footer_callback.html

at certain point if any data in the table is changed I refresh the table like so

 $.ajax({
                url: myurl,
                type: "GET",
                dataType: "html",
                success: function (data) {
                    $('#placeHere').html(data);
                },
            });

but than when i use a dropdwon then to search this table

myTable.columns(6).search(this.value).draw();

then during the redrawing in footercallback array variable in api() is empty.

                    "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;
                        };
                        Q1 = api
                            .column(1, { page: 'current' })
                            .data()
                            .reduce(function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0);

I have been strugelling with this for a while, any idea why can't i use draw() after i use ajax to refresh data in a table ?
Would appriciate any suggestions.

Check on length string results in translation of tags

$
0
0

Hi,

When I use:

                Field::inst( 'am_templateblocks.content' )
                    ->validator( Validate::maxLen( 4000, ValidateOptions::inst()
                    ->message( 'Dit veld mag maximaal 4000 karakters zijn' ) ) ),

The input of "<section>" results in the unexpected "<section>"

Why is this? Is this a bug, or can it be configered to accept tags?

reordering columns breaks keyboard based sorting

$
0
0

Demo: https://datatables.net/extensions/colreorder/examples/initialisation/simple.html

Instructions: First, confirm that keyboard based sorting is working. Tab to a column header and hit enter, it should sort ascending, hit enter again, it sorts descending. Now, reorder any column by dragging it to a new position. Tab back to a column header and hit enter. The column sorts either ascending or descending (whatever it was last sorted by). Hit enter again, the sort direction does not change.

Any workaround for this?

Edited to add: tested this in Chrome, Firefox, and Edge and they all have the same problem. No errors in javascript console.

is there a way to add working html5 tag on createdRow

$
0
0

Hello,
I have data data I use coming from ajax in json format, it works fine but the json gives me dates in timestamp and I format them in upon createdRow which works fine, the problem is when I try to search it doesn't search for the value that I have formatted but for the one that comes from my json e.g. if I type 2017 no results are shown, but from part of the timestamp it shows it. I try adding data-search with the formatted date and it adds the attributes but no result are shown in search. Is there a solution for that?

Problem with Buttons-Collections.

$
0
0

Hi all,
I have a datatable on dialog and the Collection contain: Print, PDF,...
When I double-click the "Download" button, after that the dropdown can't show again.

Please help, thanks


Server-side searching or filtering won't work (fnServerData+LINQ+DataTableParser)

$
0
0

Hi,

I'm struggling to add searching/filtering functionalities to a complex ASP.NET project involving an WSDatatable.asmx file and Zack Owens's DataTable parser.
Here is the debug page.

Every functionality of the table works fine except for searching/filtering.
When I type in the search field, this is the error I get is in the DataTableParser.cs file:

System.ArgumentException: An item with the same key has already been added

at this line of the function "FormatedList Parse()":

            list.aaData = _queriable.Where(ApplyGenericSearch)
                                    .Where(IndividualPropertySearch)
                                    .Skip(skip)
                                    .Take(take)
                                    .ToList()
                                    .AsQueryable()
                                    .Select(SelectProperties)
                                    .ToList();

(The original line was slightly modified to suit the need of the project.)

How can I search/filter this DataTable? Is it the fact that I'm getting data through the DataTable parser that makes things impossible to work?

The syntax I use in my WsDataTable.asmx.cs file is:

        [ScriptMethod(UseHttpGet=true, ResponseFormat=ResponseFormat.Json)]
        [WebMethod]
        public FormatedList GetPersonnels()
        {
            FormatedList formatedList;
            HttpRequest request = base.Context.Request;
            using (ISession session = Repository.TSession())
            {
                IQueryable<DTPersonnels> qPersonnel =
                    from p in session.Query<Personnels>()
                    select new DTPersonnels()
                    {
                        Id = p.Id,
                        NomPersonnel = p.NomPersonnel,
                        Desactive = (p.Desactiver ? "Oui" : "Non")
                    };
                if (request["sEcho"] == null)
                {
                    return null;
                }
                else
                {
                    // When typing in the search field, this line triggers the function "FormatedList Parse()" that errors
                    formatedList = (new DataTableParser<DTPersonnels>(request, qPersonnel)).Parse();
                }
            }
            return formatedList;
        }

Note (useful?): When I use YADCF filter plugin, it only populates the "select" and "autocomplete" with the items of the active page! And it crashes too when I run a search or a filter.

Thanks !

How to get datatable get data using the angularJS ng-repeat

Datatable search box not working for table?

$
0
0

Hi allen,
I am pupulating the data in table using ajax call I am able to populate but search, box is not working while I am searching there is no filtering is happening.
please tell what mistake I am doing.

Thanks

Datatable search box not working?

$
0
0

Hi allen,
I am pupulating the data in table using ajax call I am able to populate but search, box is not working while I am searching there is no filtering is happening.
please tell what mistake I am doing.

Thanks

Date Format validator doesn't work proper

$
0
0

Hi,

I used the generator and created two entries
valid from
valid until
with the German date format "dd.MM.yy".

It works fine for the online preview.

Starting the project leads to the following situation, http://prntscr.com/hvjjxp , where it is possible to store a date like 01.01.18, but not 10.01.18.

The POST request includes

data[0][gueltig_von] 01.01.18
data[0][gueltig_bis] 10.01.18

The result is

{
   "draw":null,
   "data":[

   ],
   "recordsTotal":null,
   "recordsFiltered":null,
   "error":null,
   "fieldErrors":[
      {
         "name":"gueltig_bis",
         "status":"Input not valid"
      }
   ],
   "id":null,
   "meta":{

   },
   "options":{

   },
   "files":{

   },
   "upload":{
      "id":null
   },
   "debugSql":[

   ],
   "cancelled":[

   ]
}

debugSql is empty, also I set

.Debug(true)

in the Controller.cs

The validation in the Controller.cs is

                    .Field(new Field("gueltig_von")
                            .Validator(Validation.DateFormat("dd.MM.yy"))
                            .GetFormatter(Format.DateSqlToFormat("dd.MM.yy"))
                            .SetFormatter(Format.DateFormatToSql("dd.MM.yy"))
                    )
                    .Field(new Field("gueltig_bis")
                            .Validator(Validation.DateFormat("dd.MM.yy"))
                            .GetFormatter(Format.DateSqlToFormat("dd.MM.yy"))
                            .SetFormatter(Format.DateFormatToSql("dd.MM.yy"))
                    )

The type of both dates are "date" in the MS SQL SERVER.

I suspect that there is an error in the validation for the German date format.

All the best,
Markus

problem edit

$
0
0

good, we are doing tests with the editor to see if it is good for our company and we have a problem when editing, to create it works well but when editing in the mvc part the action is not coming to edit but the data reaches 0, could you tell us what the problem is?

    var editor;

    $(document).ready(function () {
        editor = new $.fn.dataTable.Editor({
            table: "#datatable",
            ajax: {
                create: {
                    type: 'POST',
                    url: 'http://localhost:55218/task/config/add',
                },
                edit: {
                    type: 'POST',
                    url: 'http://localhost:55218/task/config/edit',
                },
                delete: {
                    type: 'POST',
                    url: 'http://localhost:55218/task/config/delete',
                }
            },
            idSrc: 'codconfig',
            fields: [
                {
                    label: "codconfig:",
                    name: "codconfig"
                },
                {
                    label: "Key:",
                    name: "key"
                },
                {
                    label: "Value:",
                    name: "value"
                }]
        });

        $('#datatable').DataTable({
            dom: "Bfrtip",
            ajax: {
                url: "http://localhost:55218/task/config/list",
                type: "GET"
            },
            serverSide: true,
            columns: [
                { data: "codconfig" },
                { data: "key" },
                { data: "value" },
            ],
            select: true,
            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit", editor: editor },
                { extend: "remove", editor: editor }
            ]
        });
    });

Is it possible to hide rows when creating table from CSV file?

$
0
0

In the same way that columnDefs can make some columns visible TRUE or FALSE, can the same be done for rows? For example, if I have a CSV file with 50 rows of data, can I just show rows 10 to 30?


Server side pagination doesn't work

$
0
0

Hi, I would like to paginate mysql results table so i added the following code:
$(function () {
$("#example1").DataTable({
"processing": true,
"serverSide": true,
"ajax": "server_processing.php"
);
});

and the server_processing.php contains my db information, table name etc... but every time i try to load the list an alert popup says:
DataTables warning: table id=example1 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Can you pls help me? Thanks

Can you make a range of column targets 'visible false', rather than list individual columns?

$
0
0

When using columnDefs, is it possible to select a range of targets instead of listing each individual.
For example, instead of listing:

        { "visible": false, "targets": [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 28 ]},

Is it possible to make visible columns 3-14 and 28?

JQuery 3.2.1 Deprecations

$
0
0

I have Datatables 1.10.16
It was said that it should not have problem with jquery 3, but it still have with focus() and blur().

JQMIGRATE: jQuery.fn.focus() event shorthand is deprecated

My jquery version is 3.2.1

Can somebody look at JQuery 3.2.1 Deprecations

Keep DataTables data in memory in-between postbacks

$
0
0

Hello,

I am using Asp.net and jQuery DataTables for GridView.

I want to keep Data as it as while postback asp.net forms.

is it possible ?

thanks
Kalpesh

Viewing all 81684 articles
Browse latest View live


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