javascript - How to sort by a second column while keeping the sorting on the first column? -
i working on table built dynamically depending on filters chosen. able sort row click. problem need first row sort stay when click on row, second row click sorted within means of first row. example have 2 columns, first name , last name.
**firstname** **lastname** bob zimmer bob anderson kathy walege kathy ball
so click on first name row. stay same since first names in order. when click on last name row want following happen.
**firstname** **lastname** bob anderson bob zimmer kathy ball kathy walege
i have working sorts 1 column @ time. using both javascript , vb.net work code.
here's javascript:
function sortcolumn(col) { __dopostback('sortby',col); }
here's vb function calls javascript function:
private function addsortlinktocolumn(byval ssortcolumn string) string dim sval string = "" sval = "<a href=""javascript:sortcolumn('" & ssortcolumn & "');""><font face=""webdings"">" if m_ssort <> "" andalso split(m_ssort, "-")(0) = ssortcolumn andalso m_ssortdrxn = "asc" sval &= "5" else sval &= "6" end if sval &= "</font></a>" return sval end function
this taking column being clicked , matching global sort variable. if match displays arrow. if fails displays down arrow.
i know need somehow keep track of first column clicked, not sure how so. have tried on vb.net side , javascript sides adding column sort doesn't me if can't first column value stay!
how can keep first column's sort , sort second column well? appreciated!
update
with of answer listed below got working! here's code:
function sortcolumn(col) { <% if m_ssort = nothing %> __dopostback('sortby', col); <% else %> __dopostback('sortby', document.getelementbyid("sortfield").value + "," + col); <% end if %> }
the m_ssort public variable on vb.net side. "sortfield" name of hidden field m_ssort value being stored.
add hidden field page called prevcol
or that. since hidden field posted form.
in postback
event handler, make sure consume hidden field , replace value clicked column.
in way have column clicked column clicked. if check value , empty know starting off.
your remove sort button clear prevcol
field ensure starting fresh.
so flow this:
first column click:
prevcol
empty sort clicked column , write identifierprevcol
field on returned page.second column click:
prevcol
has value. first sort value, sort supplied column. make sure write supplied columnprevcol
in return.xth column click: same second click. inherintly going make
prevcol
first column sorted each time.
when click remove sort button, ensure not writing value prevcol
, starting cycle over.
in way kind of caching previous column on client each response present during post back.
edit:
i thought simple alternatively entirely on client side jquery long server did not need know order of rows.
so spent time thinking how done using jquery , found bit more challenging anticipated.
with james padolsey able sort table rows, logic of sorting based on previous column bit strange.
Comments
Post a Comment