Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to add 2 extra columns for crud actions ie select and delete displaying an image in the column with a link via primary key. I cannot get it to show up or it says i have the incorrect number of columns. Table View

<table class="SearchResultsTable">
<thead>
    <tr>
        <th>
            @Html.DisplayName("User Id")
        </th>
        <th>
            @Html.DisplayName("User Email")
        </th>
        <th>
            @Html.DisplayName("User Role")
        </th>
        <th>
            @Html.DisplayName("Select")
        </th>
        <th>
            @Html.DisplayName("Delete")
        </th>
    </tr>
</thead>
<tbody>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.user_pk)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.user_email)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.user_type)
            </td>
            <td>
                <a href="@Url.Action("GetUser", "User", new { id = item.user_pk })">
                    <img src="/Content/Images/SelectIcon.gif" alt="My Image" />

                </a>
            </td>
            <td>
                <a href="@Url.Action("GetUser", "User", new { id = item.user_pk })">
                    <img src="/Content/Images/DeleteIcon.gif" alt="My Image" />

                </a>
            </td>
        </tr>
    }
</tbody>

jquery

<script type="text/javascript">

    $(document).ready(function () {
        $(".SearchResultsTable").dataTable({
            'bServerSide': true,
            'bProcessing': true,
            'sAjaxSource': '/User/FilteredUsers',
            "bJQueryUI": true,
            "bAutoWidth": false,
            "bPaginate": true,
            "sPaginationType": "full_numbers",
            "iDisplayLength": 25,
            "aoColumns": [
            { "sName": "user_pk",
                "bSearchable": false,
                "bSortable": false,
            },
            { "sName": "user_email" },
            { "sName": "user_role" },
            //{
            //    "mData": null, "bSearchable": false,
            //    "bSortable": false, "sClass": "editControl",
            //    "sDefaultContent": '<img src="/Content/Images/SelectIcon.gif"  />'
            //},
            //{
            //    "mData": null, "bSearchable": false,
            //    "bSortable": false, "sClass": "editControl",
            //    "sDefaultContent": '<img src="/Content/Images/DeleteIcon.gif"  />'
            //}

            ]

            /* make the first and last columns not sortable */

        });
    });
</script>

}

controller

    // GET: /User/Details/5
    public ActionResult FilteredUsers(jQueryDataTableParamModel param)
    {
        RestClient RestClientObject = new RestClient("http://domain");
        var request = new RestRequest("api/user/", Method.GET);
        request.AddParameter("page", param.iDisplayStart);
        request.AddParameter("pageSize", param.iDisplayLength);
        if (param.sSearch != null)
            request.AddParameter("userName", param.sSearch);

        IRestResponse<Pager<UserSummaryModel>> response =  RestClientObject.Execute<Pager<UserSummaryModel>>(request);
        IEnumerable<string[]> result = null;
        try
        {
            result = from c in response.Data.pagedSet select new[] { Convert.ToString(c.user_pk), c.user_email, c.user_type };
        }
        catch
        {
            result = Enumerable.Empty<string[]>();
        }
        return Json(new
    {

        sEco = param.sEcho,
        iTotalRecords =  response.StatusCode == HttpStatusCode.OK ? response.Data.totalRecordSize : 0,
        iTotalDisplayRecords =  response.StatusCode == HttpStatusCode.OK ? response.Data.totalRecordSize : 0,
        aaData = result
    },
   JsonRequestBehavior.AllowGet);
    }

If I do not put the extra rows in result array in controller it says i have the incorrect columns numbers.. if i leave them out of the jquery i dont get the error but the columns are not populated. Please tell me how to do this

share|improve this question
    
its this what your are looking for ? stackoverflow.com/a/13233937/617373 –  Daniel Feb 18 '13 at 12:33
    
Thanks Daniel but tried this as you can see in jquery code the commented out bit... It always says not enough columns specified unless I put it in my result server side.. –  Annmarie Inkley Feb 19 '13 at 13:13
    
result = from c in response.Data.pagedSet select new[] { Convert.ToString(c.user_pk), c.user_email, c.user_type,image, image }; I do not want to put this in my server side tag I want to be able to add the column content client side –  Annmarie Inkley Feb 19 '13 at 13:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.