Is there a way to render an ASP MVC view as a return of a AjaxSource?

Is there a way to render an ASP MVC view as a return of a AjaxSource?

theConartisttheConartist Posts: 14Questions: 3Answers: 0
edited May 2014 in DataTables

Is there a substitute that instead of rendering the json data in javascript, a new attribute in DataTablesData that contains a rendered html View? also, a DataTable class that handles the rendering?

And on the redraw of the table, renders the returned view?

I know I could use an Ajax call to render the table and call the .dataTable after but I do not know how to embed the dataTableParams capabilities this way.

Answers

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Assuming that it is returning HTML, then not built into the core. You would need to use ajax.dataSrc as a function and parse the HTML to built a Javascript array from the HTML.

    Allan

  • theConartisttheConartist Posts: 14Questions: 3Answers: 0
    edited May 2014

    What I did was:

                    fnServerData: function (sSource, aoData, fnCallback, oSettings) {
                    var table = this;
                    var renderRow = function (json) {
                        $(table[0]).find('tbody').html(json.view);
                        fnCallback(json);
                    }
    
                    oSettings.jqXHR = $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": function (json) {
                            renderRow(json);
                        }
                    })
                }
    

    where the json returned is the DataTablesData and I added an attribute view that contains the html.

    Now this error occurs "DataTables warning: Requested Unknown parameter '0' from the data source for row 0"

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    What is the value of json that you are giving to fnCallback?

    Allan

  • theConartisttheConartist Posts: 14Questions: 3Answers: 0
     return new CustomDataTablesData
            {
                iTotalRecords = totalRecords,
                iTotalDisplayRecords = filteredData.Count() + param.iDisplayStart,
                sEcho = param.sEcho,
                aaData = result.Select(r => new { r.AlgoPreference.Algo.Name, r.AlgoPreference.DisplayName, r.Value }).Cast<object>().ToArray(),
                view = view
            };
    
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    And what is the value of aaData? What is the result of the statement. It would be really useful if you could link to the page.

  • theConartisttheConartist Posts: 14Questions: 3Answers: 0
    edited August 2014

    edited - wrong post

This discussion has been closed.