Rectangle 27 5

In order to maintain the zebra stripes after a sort has taken place you need to trigger the zebra widget again.

$('#myTable')
.tablesorter({ widgets: ['zebra'] })
.bind('sortEnd', function(){
    $("#myTable").trigger("applyWidgets"); 
});

This is less of a hack, as you will be reusing the logic of the zebra widget rather than replicating it.

Note: This kind of work-around is only required in instances where the default zebra widget is failing. I have found in most circumstances that this hack is not required as the widget is operating correctly post sort.

jquery tablesorter plugin - retain alternative row colors - Stack Over...

jquery row tablesorter backcolor
Rectangle 27 1

With most browsers supporting CSS3, you don't really need to use the zebra widget anymore, unless you plan on filtering rows (see this demo).

table tbody > tr:nth-child(odd) > td,
table tbody > tr:nth-child(odd) > th {
    background-color: #f9f9f9;
}

Ya thats the thing is I do need to support filtering

Well, then you just need to use the applyWidgets method whenever the table becomes visible - e.g. see this answer on how to use tablesorter within jQuery UI tabs.

Is there any reason why it won't bother to try doing a zebra while its hidden?

It's difficult to distinguish the difference between a table row being hidden by filtering or pagination versus the row being hidden because it is within a closed tab. Also, no zebra stripe class name is applied to hidden rows because it would only add more of a delay to apply the widget after each sort - this would be especially noticeable in large tables.

javascript - Tablesorter zebra doesnt stripe till sort - Stack Overflo...

javascript jquery css html-table tablesorter
Rectangle 27 75

As of Swift 2, String doesn't conform to SequenceType. However, you can use the characters property on String. characters returns a String.CharacterView which conforms to SequenceType and so can be iterated through with a for loop:

let word = "Zebra"

for i in word.characters {
    print(i)
}
String
SequenceType
extension String: SequenceType {}

// Now you can use String in for loop again.
for i in "Zebra" {
    print(i)
}

Although, I'm sure Apple had a reason for removing String's conformance to SequenceType and so the first option seems like the better choice. It's interesting to explore what's possible though.

the reason why String doesn't conform to SequenceType is that the same String can be represented by more than one sequence of elements.

Iterate through a String Swift 2.0 - Stack Overflow

swift swift-playground swift2 xcode7
Rectangle 27 75

As of Swift 2, String doesn't conform to SequenceType. However, you can use the characters property on String. characters returns a String.CharacterView which conforms to SequenceType and so can be iterated through with a for loop:

let word = "Zebra"

for i in word.characters {
    print(i)
}
String
SequenceType
extension String: SequenceType {}

// Now you can use String in for loop again.
for i in "Zebra" {
    print(i)
}

Although, I'm sure Apple had a reason for removing String's conformance to SequenceType and so the first option seems like the better choice. It's interesting to explore what's possible though.

the reason why String doesn't conform to SequenceType is that the same String can be represented by more than one sequence of elements.

Iterate through a String Swift 2.0 - Stack Overflow

swift swift-playground swift2 xcode7
Rectangle 27 2

Before sending a UPS GraphicImage label using ZPL format to a Zebra Printer, you need to convert it from base64 string to ascii string. See the answer to How do I Encode and Decode a base64 string

//...UPS Shipment Request construction...
shipmentRequest.LabelSpecification.LabelImageFormat.Code = "ZPL";
shipmentRequest.LabelSpecification.LabelStockSize.Height = "8";
shipmentRequest.LabelSpecification.LabelStockSize.Width = "4";
//...
// Submit the Shipment Request to the UPS Ship Service
ShipmentResponse shipmentResponse = shipService.ProcessShipment(shipmentRequest);
//...Process the Shipment Response...

// The Label is encoded as Base64 Text.  Decode this to standard ASCII Text
string labelData = Base64Decode(shipmentResponse.ShipmentResults.PackageResults[0].ShippingLabel.GraphicImage);

// Write the label data to a file so it can be printed/reprinted as needed
System.IO.File.WriteAllText(@"C:\temp\UPSlabel.zpl", labelData);

The ZPL Label should be printed as RAW using a Generic Text printer driver. You can edit and probably print the label using Notepad as long as you turn off its word-wrap, margins, header/footer/page number settings. Notepad++ works.

printing - UPS ZPL Lable size issue I need small size label for my ZP4...

printing size label ups
Rectangle 27 2

Before sending a UPS GraphicImage label using ZPL format to a Zebra Printer, you need to convert it from base64 string to ascii string. See the answer to How do I Encode and Decode a base64 string

//...UPS Shipment Request construction...
shipmentRequest.LabelSpecification.LabelImageFormat.Code = "ZPL";
shipmentRequest.LabelSpecification.LabelStockSize.Height = "8";
shipmentRequest.LabelSpecification.LabelStockSize.Width = "4";
//...
// Submit the Shipment Request to the UPS Ship Service
ShipmentResponse shipmentResponse = shipService.ProcessShipment(shipmentRequest);
//...Process the Shipment Response...

// The Label is encoded as Base64 Text.  Decode this to standard ASCII Text
string labelData = Base64Decode(shipmentResponse.ShipmentResults.PackageResults[0].ShippingLabel.GraphicImage);

// Write the label data to a file so it can be printed/reprinted as needed
System.IO.File.WriteAllText(@"C:\temp\UPSlabel.zpl", labelData);

The ZPL Label should be printed as RAW using a Generic Text printer driver. You can edit and probably print the label using Notepad as long as you turn off its word-wrap, margins, header/footer/page number settings. Notepad++ works.

printing - UPS ZPL Lable size issue I need small size label for my ZP4...

printing size label ups
Rectangle 27 1

Not sure if this works for all printers but this gets the job done sending ZPL files to a Zebra label printer:

<?php 
if(($conn = fsockopen('192.168.10.112',9100,$errno,$errstr))===false){
    echo 'Connection Failed' . $errno . $errstr;
}

$data = <<<HERE
    ^XA
    ^FT50,200
    ^A0N,200,200^FDTEST^FS
    ^FT50,500
    ^A0N,200,200^FDZebra Printer^FS
    ^XZ
HERE;

#send request
$fput = fputs($conn, $data, strlen($data));

#close the connection
fclose($conn);
?>

printing - Print to network printer from PHP - Stack Overflow

php printing
Rectangle 27 4

Here's a simple example using an inheritance hierarchy.

Covariance is widely used with immutable collections (i.e. where new elements cannot be added or removed from a collection)

Given the simple class hierarchy:

public abstract class LifeForm  { }
public abstract class Animal : LifeForm { }
public class Giraffe : Animal { }
public class Zebra : Animal { }

Seemingly, a method such as this

... should accept a heterogeneous collection: (which it does)

var myAnimals = new List<LifeForm>
{
    new Giraffe(),
    new Zebra()
};
DoSomethingWithLifeForms(myAnimals); // Giraffe, Zebra

However, passing a collection of a more derived type fails!

var myGiraffes = new List<Giraffe>
{
    new Giraffe(), // "Jerry"
    new Giraffe() // "Melman"
};
DoSomethingWithLifeForms(myGiraffes); // Compile Error!
cannot convert from 'System.Collections.Generic.List<Giraffe>' to 'System.Collections.Generic.IList<LifeForm>'

Why? Because the generic parameter IList<LifeForm> is not covariant - IList<LifeForm> is invariant, and only accepts collections (which implement IList) where the parameterized type T must be LifeForm.

If I maliciously change the method implementation (but leave the same method signature), the reason why the compiler prevents passing List<Giraffe> becomes obvious:

public static void DoSomethingWithLifeForms(IList<LifeForm> lifeForms)
 {
     lifeForms.Add(new Zebra());
 }

Since IList permits adding or removal of elements, any subclass of LifeForm could thus be added to the parameter lifeForms, and would violate the type of any collection of derived types passed to the method. (Here, the malicious method would attempt to add a Zebra to var myGiraffes). Fortunately, the compiler protects us from this danger.

The solution is to ensure that a covariant generic type is used, e.g. IEnumerable (defined as IEnumerable<out T>). This prevents change to the collection, and as a result, any collection with subtype of LifeForm may now be passed to the method:

public static void DoSomethingWithLifeForms(IEnumerable<LifeForm> lifeForms)
{
    foreach (var lifeForm in lifeForms)
    {
        Console.WriteLine(lifeForm.GetType().ToString());
    }
}
DoSomethingWithLifeForms()
Zebras
Giraffes
IEnumerable<>
LifeForm

Contravariance is frequently used when functions are passed as parameters.

Here's an example of a function, which takes an Action<Zebra> as a parameter, and invokes it on a known instance of a Zebra:

public void PerformZebraAction(Action<Zebra> zebraAction)
{
    var zebra = new Zebra();
    zebraAction(zebra);
}
var myAction = new Action<Zebra>(z => Console.WriteLine("I'm a zebra"));
PerformZebraAction(myAction); // I'm a zebra
var myAction = new Action<Giraffe>(g => Console.WriteLine("I'm a giraffe"));
PerformZebraAction(myAction);
cannot convert from 'System.Action<Giraffe>' to 'System.Action<Zebra>'
var myAction = new Action<Animal>(a => Console.WriteLine("I'm an animal"));
PerformZebraAction(myAction); // I'm an animal
var myAction = new Action<object>(a => Console.WriteLine("I'm an amoeba"));
PerformZebraAction(myAction); // I'm an amoeba
Action
Action<in T>
contravariant

Although this may be non-intuitive at first (e.g. how can an Action<object> be passed as a parameter requiring Action<Zebra> ?), if you unpack the steps, you will note that the called function (PerformZebraAction) itself is responsible for passing data (in this case a Zebra instance) to the function - the data doesn't come from the calling code.

Because of the inverted approach of using higher order functions in this manner, by the time the Action is invoked, it is the more derived object instance which is invoked against the zebraAction function (passed as a parameter), which itself uses the less derived type.

c# - Covariance and contravariance real world example - Stack Overflow

c# c#-4.0 covariance
Rectangle 27 1

You could select users who are friends with both users by linking the user table to the zebra table twice:

The JOIN takes all the rows from the users table, and all the rows from the zebra table, and looks for the combinations that satisfy the ON clause. In this case, the first join finds all users who are friends with @user_id1, the second join further restricts it to users who are also friends with @user_id2.

This query will perform much faster than using subqueries will. The query would be even faster if the zebra table stored friendships in both directions, allowing you to take more advantage of table indexes, and you could remove the OR portion of the ON clauses:

SELECT u.username, u.user_colour, u.username_clean, u.user_avatar, u.user_avatar_type 
FROM users u
JOIN zebra z1 ON u.user_id = z1.user_id AND z1.friend=1 AND z1.zebra_id = @user_id1
JOIN zebra z2 ON u.user_id = z2.user_id AND z2.friend=1 AND z2.zebra_id = @user_id2
ORDER BY u.username_clean ASC

php - Merging two complex queries - Stack Overflow

php sql mysql intersection
Rectangle 27 2

So the solution ended up being to continue to use tablesorter for both the sorting and zebra, but also just independently zebra stripe the footer using jQuery by adding something like $("#tableid tr:odd").addClass("odd"); in the same ready function. Since this is exactly what the zebra widget does to begin with, the results come out exactly the same, but it now extends to the footer as well. The resulting table will be appropriately zebra striped, but the rows we want fixed to the bottom stay put.

jquery - Tablesorter: How to continue zebra into the footer - Stack Ov...

jquery html
Rectangle 27 142

Yes, you can merge them using HTML. When I create tables in .md files from Github, I always like to use HTML code instead of markdown.

Github Flavored Markdown supports basic HTML in .md file. So this would be the answer:

Markdown mixed with HTML:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
| <ul><li>item1</li><li>item2</li></ul>| See the list | from the first column|
<table>
  <tbody>
    <tr>
      <th>Tables</th>
      <th align="center">Are</th>
      <th align="right">Cool</th>
    </tr>
    <tr>
      <td>col 3 is</td>
      <td align="center">right-aligned</td>
      <td align="right">$1600</td>
    </tr>
    <tr>
      <td>col 2 is</td>
      <td align="center">centered</td>
      <td align="right">$12</td>
    </tr>
    <tr>
      <td>zebra stripes</td>
      <td align="center">are neat</td>
      <td align="right">$1</td>
    </tr>
    <tr>
      <td>
        <ul>
          <li>item1</li>
          <li>item2</li>
        </ul>
      </td>
      <td align="center">See the list</td>
      <td align="right">from the first column</td>
    </tr>
  </tbody>
</table>

This is great, but is there any way to style the list too? Remove bullets, margins, etc.? Github, for example, doesn't seem to accept a style="list-style: none" tag on the ul element.

@TreborRude No, because Markdown is not HTML actually. But if you use a library (e.g. marked), you probably have this feature (to combine HTML with markdown).

It's ok, I found out that a <span> tag with embedded <br/> tags did exactly what I was trying to do with the styled list.

@TreborRude Sure, you still can have multiple line cells. Probably it accepts <p> tags as well.

I'm happy to confirm that the first one (embedded <ul><li>foo</li></ul>) also works on Bitbucket Server.

html - How to write lists inside a markdown table? - Stack Overflow

html markdown github-flavored-markdown
Rectangle 27 142

Yes, you can merge them using HTML. When I create tables in .md files from Github, I always like to use HTML code instead of markdown.

Github Flavored Markdown supports basic HTML in .md file. So this would be the answer:

Markdown mixed with HTML:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
| <ul><li>item1</li><li>item2</li></ul>| See the list | from the first column|
<table>
  <tbody>
    <tr>
      <th>Tables</th>
      <th align="center">Are</th>
      <th align="right">Cool</th>
    </tr>
    <tr>
      <td>col 3 is</td>
      <td align="center">right-aligned</td>
      <td align="right">$1600</td>
    </tr>
    <tr>
      <td>col 2 is</td>
      <td align="center">centered</td>
      <td align="right">$12</td>
    </tr>
    <tr>
      <td>zebra stripes</td>
      <td align="center">are neat</td>
      <td align="right">$1</td>
    </tr>
    <tr>
      <td>
        <ul>
          <li>item1</li>
          <li>item2</li>
        </ul>
      </td>
      <td align="center">See the list</td>
      <td align="right">from the first column</td>
    </tr>
  </tbody>
</table>

This is great, but is there any way to style the list too? Remove bullets, margins, etc.? Github, for example, doesn't seem to accept a style="list-style: none" tag on the ul element.

@TreborRude No, because Markdown is not HTML actually. But if you use a library (e.g. marked), you probably have this feature (to combine HTML with markdown).

It's ok, I found out that a <span> tag with embedded <br/> tags did exactly what I was trying to do with the styled list.

@TreborRude Sure, you still can have multiple line cells. Probably it accepts <p> tags as well.

I'm happy to confirm that the first one (embedded <ul><li>foo</li></ul>) also works on Bitbucket Server.

html - How to write lists inside a markdown table? - Stack Overflow

html markdown github-flavored-markdown
Rectangle 27 1

A long time ago I wrote an application for printing labels to a Zebra printer, so maybe I can help. Back in the day we only had the ZPL2 API, and only printed text and simple graphics, none of this image stuff. Anyway...

My suspicion is that it is a scaling issue. That might explain why your original image is fuzzy -- perhaps the printer is automatically attempting to scale it to fit the label, and doing a poor job of it? And of course that would explain the resulting labels shown above.

What strikes me about your code above is how you get the Graphics object. One comes from the picture box; the other presumably from the printer. Keep in mind that the Graphics object is device dependent. That is, it's properties and how it prints depends on whether you're printing to a particular control (different controls can have different scaling) or to a particular printer.

Have you tried using your existing code to print to a laser printer? It may be interesting to see the results. Also see Graphics properties such as ScaleTransform.

So I am assuming that you are talking about the TextRenderer.DrawText method and trying to check the scale of that vs the printer graphics scale? I will try that and post the results.

vb.net - Printing / Graphics Problems - Stack Overflow

vb.net graphics printing vb.net-2010
Rectangle 27 1

This solution is not Unicode, but if your firmware supports it (x.14.x and higher according to the documentation) you can force the Greek windows-1253 codepage and append using the hex version of the 1253 code table for each character.

Note: Despite the name, windows-1253 does not require the Windows operating system to function with a Zebra printer.

// ^XA = Start of label
// ^XZ = End of label 
// ^CF = Font size
// ^FO = X,Y position on label
// ^CI34 = Code Page 1253 - Zebra x.14.x fimware or higher only
// ^FH = Allow "_FF" style escaped hex characters

^XA
^CF0,60
^CI34^FO50,50^FH^FD - Theta: _C8 ^FS
^CI34^FO50,100^FH^FD - Lambda: _CB ^FS
^XZ

The disadvantage of this approach is a programmer will have to either:

  • Dynamically map each Greek character to a cp1253 equivalent before preparing the ZPL message, or...
  • Use a character encoding converter to map the UTF character to the cp1253 equivalent before sending. Many programming languages have built-in methods for doing this. Warning as these may appear as strange symbols in a terminal or output stream.

So, if the printer directly supports Unicode data, that is the ideal solution, but if it doesn't, cp1253 may be a viable option.

unicode - How to print Greek characters from zpl commands - Stack Over...

unicode zpl barcode-printing zpl-ii intermec
Rectangle 27 6

If the choice was there, my first preference will be classes/other selectors. However, there are situations where inline styles are the only way to go. In other situations, just a CSS class by itself requires too much work, and other types of CSS selectors make more sense there.

Suppose you had to zebra stripe a given list or table. Instead of applying a particular class to each alternate element or row, you could simply use selectors to do the job. That will keep the code simple, but it won't be using CSS classes. To illustrate the three ways:

.alternate {
    background-color: #CCC;
}

<ul>
    <li>first</li>
    <li class="alternate">second</li>
    <li>third</li>
    <li class="alternate">fourth</li>
</ul>
.striped :nth-child(2n) {
    background-color: #CCC;
}

<ul class="striped">
    <li>first</li>
    <li>second</li>
    <li>third</li>
    <li>fourth</li>
</ul>
<ul>
    <li>first</li>
    <li style="background-color: #CCC">second</li>
    <li>third</li>
    <li style="background-color: #CCC">fourth</li>
</ul>

The second way looks the most portable and encapsulated to me. To add or remove stripes from any given container element, simply add or remove the striped class.

However, there are cases where inline styles not only make sense, but are the only way to go. When the set of possible values is huge, it will be stupid to try to make classes in advance for each possible state. For example, a UI that allows the user to dynamically place certain items anywhere on the screen by dragging. The item will have to be positioned absolutely or relatively with actual coordinates such as:

<div style="position: absolute; top: 20px; left: 49px;">..</div>

Surely, we could use classes for each possible position the div can take, but that's not recommended. And one can easily see why:

.pos_20_49 {
    top: 20px;
    left: 49px;
}
.pos_20_50 {
    top: 20px;
    left: 50px;
}
// keep going for a million such classes if the container size is 1000x1000 px

<div class="pos_20_49">..</div>

css - Inline Styles vs Classes - Stack Overflow

css css3 inline-styles
Rectangle 27 6

If the choice was there, my first preference will be classes/other selectors. However, there are situations where inline styles are the only way to go. In other situations, just a CSS class by itself requires too much work, and other types of CSS selectors make more sense there.

Suppose you had to zebra stripe a given list or table. Instead of applying a particular class to each alternate element or row, you could simply use selectors to do the job. That will keep the code simple, but it won't be using CSS classes. To illustrate the three ways:

.alternate {
    background-color: #CCC;
}

<ul>
    <li>first</li>
    <li class="alternate">second</li>
    <li>third</li>
    <li class="alternate">fourth</li>
</ul>
.striped :nth-child(2n) {
    background-color: #CCC;
}

<ul class="striped">
    <li>first</li>
    <li>second</li>
    <li>third</li>
    <li>fourth</li>
</ul>
<ul>
    <li>first</li>
    <li style="background-color: #CCC">second</li>
    <li>third</li>
    <li style="background-color: #CCC">fourth</li>
</ul>

The second way looks the most portable and encapsulated to me. To add or remove stripes from any given container element, simply add or remove the striped class.

However, there are cases where inline styles not only make sense, but are the only way to go. When the set of possible values is huge, it will be stupid to try to make classes in advance for each possible state. For example, a UI that allows the user to dynamically place certain items anywhere on the screen by dragging. The item will have to be positioned absolutely or relatively with actual coordinates such as:

<div style="position: absolute; top: 20px; left: 49px;">..</div>

Surely, we could use classes for each possible position the div can take, but that's not recommended. And one can easily see why:

.pos_20_49 {
    top: 20px;
    left: 49px;
}
.pos_20_50 {
    top: 20px;
    left: 50px;
}
// keep going for a million such classes if the container size is 1000x1000 px

<div class="pos_20_49">..</div>

css - Inline Styles vs Classes - Stack Overflow

css css3 inline-styles
Rectangle 27 5

When iterating a Hashmap, there will be no guarantee about the iteration order. Now why is that?

They're inserted not in order of when they occurred, but what value they hash to.

For example, suppose that we have a hash function h(x) which returns 127 for the string "Hello", and 12 for "Zebra". If we enter those keys into our hash map, the order in which they are read out is "Zebra" -> (whatever value attached), then "Hello" -> (whatever value attached).

Mind you, this is a simplified variation on what hashing actually does and represents. It could be the case that there is a collision on a hash value, and that collision needs to be addressed in some fashion. This is meant as primer; the key is inserted in order of its hash, but if your hash function has flaws or you don't have a good value for your object's hash, then you may run into aberrant behavior.

A hash operation is not dependent on the size of the overall collection. Recall that h(x) only operates based on the single value we're trying to insert. If we're inserting elements into a TreeMap, we have to consider what natural ordering they're in - and this involves traversing the structure to find a spot to insert into, and may also involve rebalancing or reorganizing the structure to ensure that balance is preserved.

There's a lot more to the source for TreeMap's put method.

public V put(K key, V value) {
    Entry<K,V> t = root;
    if (t == null) {
        compare(key, key); // type (and possibly null) check

        root = new Entry<>(key, value, null);
        size = 1;
        modCount++;
        return null;
    }
    int cmp;
    Entry<K,V> parent;
    // split comparator and comparable paths
    Comparator<? super K> cpr = comparator;
    if (cpr != null) {
        do {
            parent = t;
            cmp = cpr.compare(key, t.key);
            if (cmp < 0)
                t = t.left;
            else if (cmp > 0)
                t = t.right;
            else
                return t.setValue(value);
        } while (t != null);
    }
    else {
        if (key == null)
            throw new NullPointerException();
        @SuppressWarnings("unchecked")
            Comparable<? super K> k = (Comparable<? super K>) key;
        do {
            parent = t;
            cmp = k.compareTo(t.key);
            if (cmp < 0)
                t = t.left;
            else if (cmp > 0)
                t = t.right;
            else
                return t.setValue(value);
        } while (t != null);
    }
    Entry<K,V> e = new Entry<>(key, value, parent);
    if (cmp < 0)
        parent.left = e;
    else
        parent.right = e;
    fixAfterInsertion(e);
    size++;
    modCount++;
    return null;
}

How do LinkedHashMaps work, how do they maintain the order? Is it because they have a doubly-linked list that contains the information about which entry is stored before and after an entry?

  • Keys are still grouped together in a hash structure to ensure their uniqueness.
  • The order in which they are inserted is preserved by a FIFO structure, like a linked list.

Think of it like this: you use the hash function to ensure that the key is unique, and if it is, you then immediately insert it and its value into the list. This way, both the ordering and the uniqueness are preserved.

HashMap
String

Let me go ahead and clarify that. Those should be keys, not values.

This clarified a lot for me, thank you.

How do Hashmaps, Treemaps and LinkedHashmaps work in Java? - Stack Ove...

java hashmap treemap linkedhashmap
Rectangle 27 2

The reason why the cast

var listOfX = new List<X>();
ListOf<Y> ys = (List<Y>)listOfX; // Compile error: Cannot implicitly cast X to Y

is not possible is because the generic List<T> is invariant and thus it doesn't matter whether X derives from Y).

See here for the reason why mutable collections like List cannot support covariance.*

However, if mutable collections are not required, an upcast such as

IEnumerable<Animal> animals = giraffes;

is possible, if Giraffe derives from Animal, given that IEnumerable<T> supports covariance of T - this makes sense given that IEnumerable infers that the collection cannot be changed.

.Cast<T>

As others have mentioned, .Cast<T> can be applied to a collection to project a new collection of elements casted to T, however doing so will throw an InvalidCastException if the cast on one or more elements is not possible (which would be the same behaviour as doing the explicit cast in the OP's foreach loop).

Filtering and Casting with OfType<T>

If the input list contains elements of different, incompatable types, the potential InvalidCastException can be avoided by using .OfType<> instead of .Cast<>. (.OfType<> checks to see whether an element can be converted to the target type.)

Note also, that if the OP had written: (note the explicit Y y in the foreach)

List<Y> ListOfY = new List<Y>();

foreach(Y y in ListOfX)
{
    ListOfY.Add(y);
}

that any element which is not a Y, or which cannot be converted to a Y will be skipped and eliminated from the resulting list. i.e. foreach(Y y in ListOfX){ ... Add(y) } is equivalent to ListOfX.OfType<Y>

For example, given the simple (C#6) class hierarchy:

public abstract class Animal
{
    public string Name { get;  }
    protected Animal(string name) { Name = name; }
}

public class Elephant :  Animal
{
    public Elephant(string name) : base(name){}
}

public class Zebra : Animal
{
    public Zebra(string name)  : base(name) { }
}

When working with a collection of mixed types:

foreach(Elephant animal in mixedAnimals)
{
     castedAnimals.Add(animal);
}
// Ellie

and

var castedAnimals = mixedAnimals.OfType<Elephant>()
    .ToList();
// Ellie

filter only the Elephants - i.e. Zebras are eliminated.

User defined conversion operators are only used at compile-time*, so even if a conversion operator between say Zebra and Elephant was made available, the above run time behaviour of the approaches to conversion wouldn't change.

If we add a conversion operator to convert a Zebra to an Elephant:

public class Zebra : Animal
{
    public Zebra(string name) : base(name) { }
    public static implicit operator Elephant(Zebra z)
    {
        return new Elephant(z.Name);
    }
}

Instead, given the above conversion operator, the compiler will be able to change the type of the below array from Animal[] to Elephant[], given that the Zebras can be now converted to a homogeneous collection of Elephants:

var compilerInferredAnimals = new []
{
    new Zebra("Zed"),
    new Elephant("Ellie")
};

*As mentioned by Eric, the conversion operator can however be accessed by resorting to dynamic:

var mixedAnimals = new Animal[] // i.e. Polymorphic collection
{
    new Zebra("Zed"),
    new Elephant("Ellie")
};

foreach (dynamic animal in mixedAnimals)
{
    castedAnimals.Add(animal);
}
// Returns Zed, Ellie

c# - Shorter syntax for casting from a List to a List? - Stack O...

c# list casting ienumerable
Rectangle 27 1

Can you please try following sequence after the ajax call:

$("#myStoreStatusTbl").trigger("update");
var sorting = [[3,1],[10,0],[0,0]]; 
// sort on the list 
$("#myStoreStatusTbl").trigger("sorton",[sorting]);
sorton

thanks. That worked. It not only re-did the sorting but it also re did the zebra rows and everything that i asked for in the initialisation. Is what you specified above documented anywhere on the tablesorter website?

Oh..that's really good. Even I haven't found it in any specific documentation but it's mentioned in one of demo example related to appending additional rows via Ajax. Sorry I don't remember the exact Url though.

jquery - How to re-init tablesorter - Stack Overflow

jquery tablesorter
Rectangle 27 1

The CSS specification states that the column background is applied only if both the cell and row have transparent backgrounds (see http://www.w3.org/TR/CSS21/tables.html#columns).

You have to set your color on the tr or the td.

td:first-child {background: grey}

Another solution I decided to use was to set the background-colour of the alternate stripes to for example rbga(200,200,200, 0.1). This way, you can see the highlight through the zebra stripes. Very fast and clean solution with few downsides.

html - colgroup background color not override tr background color - St...

html css