Place datatable_wrapper manually?

Place datatable_wrapper manually?

sresre Posts: 3Questions: 0Answers: 0
edited November 2011 in General
Hi there!

I am using datatables together with asp.net mvc3 and I've written a couple of helper methods that ease the creation of a table. In other words, you can set the properties for the table in a special class and .Net generates the specific code.

This is the .Net sourcecode to generate the table:
[code]
@Html.GridBegin(gridModel.ID, gridModel.GridInfo)



Name


Wert




@For Each arg In Model.Arguments
@

@arg.TechnicalName


@arg.Value


Next

@Html.GridEnd
[/code]

Short Explanation:
The @HTML.GridBegin generates something like
The @HTML.GridEnd generates

The GridInfo as common infos for the layout:
[code]
gridModel.GridInfo.Width = "100% !Important"
gridModel.GridInfo.Align = "center"
[/code]

My problem is that I have only influence on creating the tag to set the width but not on the around (datable_wrapper). That's why my width in the table (like 100%) has no impact because it gets covered by the div around.

My questions now are:

* Is it possible to force my table width anyhow (I don't want to use a class for that)
* Is it possible to create the manually. I've tried to create my own but than datatables adds his own so I have two at the end.

Hope it is clear what I want to achieve.

Thanks for any help.
Sascha

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    wouldn't it be easier to apply CSS to the div?

    [code]
    .dataTables_wrapper {
    width: 100%;
    }
    [/code]
  • sresre Posts: 3Questions: 0Answers: 0
    Easier for sure but from a coding perspective not optimal.

    What I am doing is to a write a reusable grid component. The page itself should have the same look and feel for every table. That's why I've placed the general layout settings for the table in a css file. There are only a few couple of things that are depending on the concrete table, like width. I want to avoid to mix my css infos. One part being in the css file and one beeing at the top of the page.
  • sresre Posts: 3Questions: 0Answers: 0
    The best solution for me would be if the datatable script could check whether the wrapper already exists or not. The second best would be, if there are some configuration properties for the div like width.
  • justStevejustSteve Posts: 49Questions: 8Answers: 1
    Would be very interested to see how your Helper classes have developed. I'm facing an upgrade of my controller code and would dearly love to see how others feed the DT.

    thx
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    > The best solution for me would be if the datatable script could check whether the wrapper already exists or not.

    There is no option for this in DataTables - nor is there likely to be. DataTables uses progressive enhancement - so it assumes only a basic HTML table and then works on that, adding DOM elements as needed.

    > The second best would be, if there are some configuration properties for the div like width.

    What's what CSS is for, as fbas points point :-). It might not be optimal in terms of the amount of code, but separating business logic, semantic structure and layout from each other is certainly best practice.

    An alternative approach if you can't use CSS for it is to set the wrapper's style properties in Javascript after the DataTables has been initialised.

    Allan
This discussion has been closed.