15

Please look at my problem below:

I use in my MVC-Web-Applikation the jquery datatables. When i display only 8 columns, everything works fine. But with 1 more column, i get the ajax-error-message, see title.

The controller wokrs fine, because the 8 columns work fine. Here my code of the view:

<script type="text/javascript">
    $(document).ready(function () {
        var table = $('#example').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": "@Url.Action("List", "DFS_Akustik")",
            "columns": [
                { "data": "ID" },
                { "data": "MessID" },
                { "data": "KL_ID" },
                { "data": "MP_ID" },
                { "data": "LwLin50ss" },
                { "data": "LwLin63ss" },
                { "data": "LwLin80ss" },
                { "data": "LwLin100ss" },
                //{ "data": "LwLin125ss" },
            ],
        });
    });
</script>

You can the, that the last columns is not active, then:

http://ziehl-abegg.com/files/work.jpg

When i delte the // of the last column, then:

http://ziehl-abegg.com/files/work_not.jpg

How can i solve this problem?? Please help me... I look for a solution, since Monday, the whole day!!

Thank you.

Greetz Vegeta_77

Vegeta_77
  • 464
  • 1
  • 5
  • 20

3 Answers3

10

I have it, my friends!!!!!!!!!!!!!!!!!!!!!!! Very NICE :-)

Here is the Solution:

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "scripts/post.php",
            "type": "POST"
        },
        "columns": [
            { "data": "first_name" },
            { "data": "last_name" },
            { "data": "position" },
            { "data": "office" },
            { "data": "start_date" },
            { "data": "salary" }
        ]
    } );
} );

I had just to edit the "ajax". When you use the "type" "POST", then it works.

Thank you very much.

Greetz Vegeta_77

Vegeta_77
  • 464
  • 1
  • 5
  • 20
  • Had exactly the same problem. Any idea why this fixes the issue? – DaveF Nov 04 '15 at 11:52
  • 3
    We've hit this problem, too. As far as I can tell, it's because the generated callback exceeds the 2048 character limit for GET requests. This is not a hard limit per the standard, but many web servers enforce it. – vaFyreHeart Mar 01 '16 at 00:59
  • 1
    Perfect..:) you saved a lot of time. I always love this feeling even i resolve small issue. – Krishna ijjada Oct 05 '16 at 07:34
0

Good morning. Here the HTML / table header:

<div style="width: auto; height: 750px; overflow-x: auto; overflow-y: auto;">
    <table id="example" class="table display" cellspacing="0">
        <thead>
            <tr>
                <th>ID</th>
                <th>MessID</th>
                <th>KL_ID</th>
                <th>MP_ID</th>
                <th>LwLin50ss</th>
                <th>LwLin63ss</th>
                <th>LwLin80ss</th>
                <th>LwLin100ss</th>
                @*<th>LwLin125ss</th>*@
            </tr>
        </thead>
    </table>
</div>

The server side result is good, look:

http://ziehl-abegg.com/files/ServerSide.jpg

@Sippy. I don't understand our second question.

The names are all correct, look at the third picture/link. Here is the methode "List" from the controller:

public JsonResult List([ModelBinder(typeof(DataTablesBinder))] 
IDataTablesRequest requestModel)
{
List<View_DFS_Akustik> myOriginalDataSet = dbman.View_DFS_Akustik.ToList();
List<View_DFS_Akustik> myFilteredData = dbman.Set<View_DFS_Akustik>().FullTextSearch(requestModel.Search.Value).ToList();

//Apply filter to your dataset based only on the columns that actually have a search value.
foreach (var column in requestModel.Columns.GetFilteredColumns())
{
    string query = column.Data + ".Contains(\"" + column.Search.Value + "\")";
    myFilteredData = myFilteredData.Where(query).ToList();
}

//Set your dataset on the same order as requested from client-side either directly on your SQL code or easily
//into any type or enumeration.
bool isSorted = false;
foreach (var column in requestModel.Columns.GetSortedColumns())
{
    if (!isSorted)
    {
        // Apply first sort.
        if (column.SortDirection == Column.OrderDirection.Ascendant)
            myFilteredData = myFilteredData.OrderBy(column.Data).ToList();
        else
            myFilteredData = myFilteredData.OrderBy(column.Data + " descending").ToList();

        isSorted = true;
    }
    else
    {
        if (column.SortDirection == Column.OrderDirection.Ascendant)
            myFilteredData = myFilteredData.OrderBy(column.Data).ToList();
        else
            myFilteredData = myFilteredData.OrderBy(column.Data + " descending").ToList();
    }
}

var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count()), JsonRequestBehavior.AllowGet);
}

THX. Vegeta_77

brooksrelyt
  • 3,925
  • 5
  • 31
  • 54
Vegeta_77
  • 464
  • 1
  • 5
  • 20
0
I was getting the error : DataTables warning: table id=myTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7  like this i checked my complete code twisly then i finally

This is my code :
var dtable;
$(document).ready(function () {
    var dtable = $('#myTable').DataTable(
        {
            "ajax": {
                "url":"~/Admin/Product/AllProducts"
            },
            "columns": [
                { "data": "name" },
                { "data": 'description' },
                { "data": "price" }                         
            ]
        });
});  for retrive data through ajax it renders data 

i changed
        "ajax": {
            "url": "../Admin/Product/AllProducts"
        }
try this code in your url : "../"  
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 02 '23 at 09:38