如果在网格/层次网格中出现空白字段,如何在kendo ui中正确排序?

时间:2015-06-22 13:28:26

标签: kendo-ui kendo-grid

在Kendo Grid的情况下,有网格填充空字段的情况,如图所示。在这种情况下,排序会发生变化,并且不会按预期运行。 我的问题是空白字段。那些应该在第一次或最后一次排序时出现,但这些都是来到这里。任何想法如何克服这个?

这是我到目前为止所尝试的内容:

  -(void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect
{

    CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
    // Prepare the text using a Core Text Framesetter
    CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);


    CGMutablePathRef framePath = CGPathCreateMutable();
    CGPathAddRect(framePath, NULL, frameRect);




    CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
    CFAttributedStringReplaceString (attrString,CFRangeMake(0, 0), stringRef);


    CGColorRef _red=[UIColor redColor].CGColor;

    CFAttributedStringSetAttribute(attrString, CFRangeMake(0, [textToDraw length]),kCTForegroundColorAttributeName, _red);



    // Get the frame that will do the rendering.
    CFRange currentRange = CFRangeMake(0, 0);
    CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
    CGPathRelease(framePath);

    // Get the graphics context.
    CGContextRef    currentContext = UIGraphicsGetCurrentContext();

    // Put the text matrix into a known state. This ensures
    // that no old scaling factors are left in place.
    CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);


    // Core Text draws from the bottom-left corner up, so flip
    // the current transform prior to drawing.
    CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
    CGContextScaleCTM(currentContext, 1.0, -1.0);

    // Draw the frame.
    CTFrameDraw(frameRef, currentContext);

    CGContextScaleCTM(currentContext, 1.0, -1.0);
    CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);


    CFRelease(frameRef);
    CFRelease(stringRef);
    CFRelease(framesetter);


}
$(document).ready(function() {
    $("#grid").kendoGrid({
        dataSource: {
            data: [
                { FirstName: 'Alphy', NumberColumn: 10},
                { FirstName: 'Betty', NumberColumn: 5},
                { FirstName: 'Ashish', NumberColumn: ""},
                { FirstName: 'Carlos', NumberColumn: -61},
                { FirstName: 'zebra', NumberColumn: -7},
                { FirstName: 'Ketty', NumberColumn: 5},
                { FirstName: 'alpha', NumberColumn: ""},
                { FirstName: 'Loren', NumberColumn: 5},
                { FirstName: 'Brian', NumberColumn: 5}
            ]
        },
        sortable: {
            mode: "single",
            allowUnsort: false
        },
        columns: [
            {
                field: "FirstName",
                title: "First Name"
            },
            {
                field: "NumberColumn",
                title: "Number Column"
            }
        ]
    });
});

Click here for JS Fiddle for the above code

1 个答案:

答案 0 :(得分:1)

排序看起来像一个错误,因为您将empty string ("")发送到网格。在这种情况下,您无法将intstring进行比较。

您需要发送null值才能使其正常运行。

2种可能方式:

1)您可以通过改变您的dataSource来执行此操作:

{ FirstName: 'Alphy', NumberColumn: 10},
{ FirstName: 'Betty', NumberColumn: 5},
{ FirstName: 'Ashish', NumberColumn: null},
{ FirstName: 'Carlos', NumberColumn: -61},
{ FirstName: 'zebra', NumberColumn: -7},
{ FirstName: 'Ketty', NumberColumn: 5},
{ FirstName: 'alpha', NumberColumn: null},
{ FirstName: 'Loren', NumberColumn: 5},
{ FirstName: 'Brian', NumberColumn: 5}

JSFiddle:http://jsfiddle.net/ghorg12110/pwmtzq81/6/

2)您可以将数据更改为schema

data: [
    { FirstName: 'Alphy', NumberColumn: 10},
    { FirstName: 'Betty', NumberColumn: 5},
    { FirstName: 'Ashish', NumberColumn: ""},
    { FirstName: 'Carlos', NumberColumn: -61},
    { FirstName: 'zebra', NumberColumn: -7},
    { FirstName: 'Ketty', NumberColumn: 5},
    { FirstName: 'alpha', NumberColumn: ""},
    { FirstName: 'Loren', NumberColumn: 5},
    { FirstName: 'Brian', NumberColumn: 5}
],
schema: {
    data: function (response) {
        for (var i = 0; i < response.length; i++) {
            if (response[i].NumberColumn === "") {
                response[i].NumberColumn = null;
            }
        }
        return response;
    }
}

JSFiddle:http://jsfiddle.net/ghorg12110/pwmtzq81/7/