Sort columns using jQuery Flexigrid

Is there a way to mark jQuery Flexigrid columns as sortable if I don't define them in a row?

i.e. I know I can do it

$("#flex1").flexigrid( { colModel: [ { display: 'Col1', name: 'Col1', sortable: true }, { display: 'Col2', name: 'Col2', sortable: true } }); 

But I am building the grid in the same way as:

 $("#flex1").flexigrid(); 

and then just use the repeater control to display the table that jQuery will style:

 <table id="flex1" > <tr> <th>Col1 /th> ... ... <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <tr> <td><%# Eval("Col1") %></td> ... 
+4
source share
2 answers

You probably want to generate a colModel value. You can use the same thing that you use to create HTML. i.e,

 $('#whatnot').flexigrid({ ... colModel: [ <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> {display: <%# Eval("Col1") %>, name : <%# Eval("Col1") %>, sortable : true, align: 'left', width: '80'} 

(I don't know the details of how the ASP template language works, but you get the gist.)

Alternatively, you could build a table the way you do, and then traverse the DOM with jquery to create a colModal value in Javascript.

+1
source

I really have not used this plugin, but from what I see there is a function for changing the parameters after initialization.

 var item = $("#flex1"); item.flexOptions({ colModel: [ {display: 'Col1', name: 'Col1', sortable: true}, {display: 'Col2', name: 'Col2', sortable: true} ] }); // you probably need to reload the grid after updating options item.flexReload(); 

Unfortunately, this plugin does not have documentation, so this is more of an assumption, but a guaranteed solution. I just realized that this could work from the source code.

0
source

Source: https://habr.com/ru/post/1285938/


All Articles